From 197eae3079205e5044f30fafdb86232cab11d2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B1=8C=E6=9D=82?= <1147192855@qq.com> Date: Fri, 19 Dec 2025 17:49:04 +0800 Subject: [PATCH] =?UTF-8?q?ios=20=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flutter_build_ios_onmac.command | 96 +++++++++++++++++-- 1 file changed, 87 insertions(+), 9 deletions(-) diff --git a/making_school_asignment_app/flutter_build_ios_onmac.command b/making_school_asignment_app/flutter_build_ios_onmac.command index 3bd0bfd..6e86c84 100755 --- a/making_school_asignment_app/flutter_build_ios_onmac.command +++ b/making_school_asignment_app/flutter_build_ios_onmac.command @@ -11,6 +11,10 @@ PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)" echo "Project dir: $PROJECT_DIR" +# To save credentials in macOS Keychain for non-interactive uploads, run: +# security add-generic-password -s "TransporterCredentials" -w "you@example.com:app-specific-password" -a transporter -U +# The script will read that item and expect the stored password string in the form: "APPLE_ID:APPLE_PASSWORD" + force_delete() { local target="$1" local max_retries=3 @@ -61,21 +65,95 @@ if ! flutter packages pub run build_runner build --delete-conflicting-outputs; t echo "build_runner failed or not present — continuing" fi -echo "Building iOS release..." -if ! flutter build ios --release; then - echo "iOS build failed" +echo "Building iOS IPA (verbose)..." +if ! flutter build ipa --release --verbose; then + echo "IPA build failed" exit 1 fi -OUTPUT_DIR="$PROJECT_DIR/build/ios/iphoneos" -echo "Opening iOS build output directory: $OUTPUT_DIR" -if [ -d "$OUTPUT_DIR" ]; then - open "$OUTPUT_DIR" +# Try to find the generated .ipa (searching under build/) +IPA_PATH="$(find "$PROJECT_DIR/build" -type f -name '*.ipa' -print -quit || true)" +if [ -z "$IPA_PATH" ]; then + echo "No .ipa found in build output" + echo "Build finished but no IPA to upload. Exiting." + exit 0 +fi + +echo "Found IPA: $IPA_PATH" + +# Upload via Transporter (if installed). Prefer environment vars APPLE_ID and APPLE_PASSWORD (app-specific password). +ITMS_TRANSPORTER="/Applications/Transporter.app/Contents/itms/bin/iTMSTransporter" +if [ -x "$ITMS_TRANSPORTER" ]; then + echo "Using Transporter at $ITMS_TRANSPORTER" + + # Read credentials from env, then try macOS Keychain, otherwise prompt + if [ -z "${APPLE_ID:-}" ] || [ -z "${APPLE_PASSWORD:-}" ]; then + # Try to read combined credentials from Keychain (service: TransporterCredentials) + if command -v security >/dev/null 2>&1; then + KC_PAIR="$(security find-generic-password -s "TransporterCredentials" -w 2>/dev/null || true)" + if [ -n "$KC_PAIR" ]; then + # Expect stored value in form: appleid:app-specific-password + APPLE_ID="${KC_PAIR%%:*}" + APPLE_PASSWORD="${KC_PAIR#*:}" + if [ -n "${APPLE_ID}" ] && [ -n "${APPLE_PASSWORD}" ]; then + echo "Credentials loaded from Keychain (service: TransporterCredentials)." + else + # clear if parsing failed + APPLE_ID="" + APPLE_PASSWORD="" + fi + fi + fi + + if [ -z "${APPLE_ID:-}" ] || [ -z "${APPLE_PASSWORD:-}" ]; then + echo "Provide App Store Connect credentials for upload. You can set APPLE_ID and APPLE_PASSWORD (app-specific password) in the environment or save a keychain item named 'TransporterCredentials' to avoid prompts." + read -p "Apple ID (email): " APPLE_ID + read -s -p "App-specific password (will not echo): " APPLE_PASSWORD + echo + fi + fi + + echo "Uploading $IPA_PATH to App Store Connect (this may take a while)..." + # Try transporter with a small retry loop + UPLOAD_EXIT=0 + MAX_UPLOAD_TRIES=2 + for try in $(seq 1 $MAX_UPLOAD_TRIES); do + echo "Transporter upload attempt $try of $MAX_UPLOAD_TRIES..." + if "$ITMS_TRANSPORTER" -m upload -u "$APPLE_ID" -p "$APPLE_PASSWORD" -f "$IPA_PATH"; then + echo "Upload succeeded" + UPLOAD_EXIT=0 + break + else + UPLOAD_EXIT=$? + echo "Transporter upload attempt $try failed (exit $UPLOAD_EXIT)" + # small delay before retry + sleep $((try * 2)) + fi + done + + if [ $UPLOAD_EXIT -ne 0 ]; then + echo "Transporter upload failed after $MAX_UPLOAD_TRIES attempts (exit $UPLOAD_EXIT)." + echo "Opening Transporter app so you can upload the IPA manually..." + # Try to open Transporter GUI with the IPA as argument (may import the file) + if command -v open >/dev/null 2>&1; then + if open -a Transporter "$IPA_PATH" 2>/dev/null; then + echo "Transporter app opened. Please complete the upload there." + else + echo "Failed to open Transporter with the IPA. Opening Transporter app without file..." + open -a Transporter || true + echo "Transporter opened. Please drag the IPA ($IPA_PATH) into the app to upload." + fi + else + echo "Cannot open Transporter GUI: 'open' command not found. Please upload IPA manually: $IPA_PATH" + fi + # Do not exit with error here so the script can finish and user can manually complete upload + fi else - echo "iOS build output directory does not exist: $OUTPUT_DIR" + echo "Transporter not found at $ITMS_TRANSPORTER. Please install Transporter app from the Mac App Store or upload the IPA manually." + echo "IPA path: $IPA_PATH" fi echo "All steps completed successfully!" -echo "iOS output (if built): $OUTPUT_DIR" +echo "IPA: $IPA_PATH" exit 0