#!/usr/bin/env bash # Build the web bundle + iOS app and install it on a connected iPhone. # # Works with the free Personal Team: on first use the app is built through # Xcode for this device, which registers it in the provisioning profile # (`flutter install` fails there with "This provisioning profile cannot be # installed on this device"). # Personal Team builds expire after 7 days: just run this again. # # Usage: ./scripts/install_ios.sh [device-id] (default: first iPhone found) set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT" DEVICE="${1:-}" if [ -z "$DEVICE" ]; then DEVICE="$(flutter devices --machine 2>/dev/null | python3 -c ' import json, sys devs = [d for d in json.load(sys.stdin) if d.get("targetPlatform") == "ios" and not d.get("emulator")] print(devs[0]["id"] if devs else "")')" fi if [ -z "$DEVICE" ]; then echo "No iPhone found. Connect it (cable or same Wi-Fi) and unlock it." >&2 exit 1 fi echo "==> Device: $DEVICE" ./scripts/build_web.sh # Native-asset frameworks (e.g. objective_c) live in build/native_assets/ios and # Flutter's cache does not tell simulator and device builds apart: after a # simulator build the iPhone would get a simulator binary and reject the app. rm -rf .dart_tool/flutter_build build/native_assets/ios echo "==> Flutter iOS build (device)" flutter build ios --release APP=build/ios/iphoneos/Runner.app # The free Personal Team profile must list this iPhone. If it does not yet, # build once through Xcode so it registers the device in the profile. if ! security cms -D -i "$APP/embedded.mobileprovision" 2>/dev/null | grep -q "$DEVICE"; then echo "==> Registering the device in the provisioning profile (Xcode build)" xcodebuild -workspace ios/Runner.xcworkspace -scheme Runner -configuration Release \ -destination "id=$DEVICE" -allowProvisioningUpdates -allowProvisioningDeviceRegistration \ -derivedDataPath build/ios-device -quiet build APP=build/ios-device/Build/Products/Release-iphoneos/Runner.app fi echo "==> Installing" xcrun devicectl device install app --device "$DEVICE" "$APP" echo "==> Launching (first time: trust the developer on the phone, see README)" xcrun devicectl device process launch --device "$DEVICE" com.sagifer.skycontour || true