fix(ios): auto-detect available iPhone simulator for builds

Fixed build script to automatically detect and use available simulators:

Simulator Detection:
- Auto-detects first available iPhone simulator if none specified
- Falls back to generic destination if no iPhones found
- Lists available devices in error messages

Build Destination:
- Uses specific device name when available
- Falls back to generic destination for compatibility
- Handles both named devices and generic destinations

Fixes:
- No longer hardcodes 'iPhone 15 Pro' (which may not exist)
- Works with any available iPhone simulator
- Better error messages showing available devices

Usage:
- ./scripts/build-and-deploy.sh              # Auto-detect
- ./scripts/build-and-deploy.sh 'iPhone 17'  # Specify device

Result: Build script now works with any available simulator
This commit is contained in:
Matthew Raymer
2025-11-11 19:46:56 -08:00
parent d7fe746b6b
commit a6b48013ab

View File

@@ -77,15 +77,28 @@ fi
log_info "Using CocoaPods: $POD_CMD" log_info "Using CocoaPods: $POD_CMD"
# Get simulator device (default to iPhone 15 Pro) # Get simulator device (default to first available iPhone, or user-specified)
SIMULATOR_DEVICE="${1:-iPhone 15 Pro}" if [ -z "$1" ]; then
log_info "Using simulator: $SIMULATOR_DEVICE" # Auto-detect first available iPhone simulator
SIMULATOR_DEVICE=$(xcrun simctl list devices available | grep -i "iPhone" | head -1 | sed 's/.*(\(.*\))/\1/' | xargs || echo "")
# Boot simulator if [ -z "$SIMULATOR_DEVICE" ]; then
log_step "Booting simulator..." # Fallback to generic simulator
if xcrun simctl list devices | grep -q "$SIMULATOR_DEVICE.*Booted"; then SIMULATOR_DEVICE="Any iOS Simulator Device"
log_info "Simulator already booted" log_warn "No iPhone simulators found, using generic destination"
else
log_info "Auto-detected simulator: $SIMULATOR_DEVICE"
fi
else else
SIMULATOR_DEVICE="$1"
log_info "Using specified simulator: $SIMULATOR_DEVICE"
fi
# Boot simulator (only if specific device name provided)
if [ "$SIMULATOR_DEVICE" != "Any iOS Simulator Device" ] && [ "$SIMULATOR_DEVICE" != "generic/platform=iOS Simulator" ]; then
log_step "Booting simulator..."
if xcrun simctl list devices | grep -q "$SIMULATOR_DEVICE.*Booted"; then
log_info "Simulator already booted"
else
if xcrun simctl boot "$SIMULATOR_DEVICE" 2>/dev/null; then if xcrun simctl boot "$SIMULATOR_DEVICE" 2>/dev/null; then
log_info "✓ Simulator booted" log_info "✓ Simulator booted"
else else
@@ -94,6 +107,7 @@ else
open -a Simulator open -a Simulator
sleep 5 sleep 5
fi fi
fi
fi fi
# Install CocoaPods dependencies # Install CocoaPods dependencies
@@ -120,11 +134,20 @@ SCHEME="App"
CONFIG="Debug" CONFIG="Debug"
SDK="iphonesimulator" SDK="iphonesimulator"
# Use generic destination if device name is generic, otherwise use specific device
if [ "$SIMULATOR_DEVICE" = "Any iOS Simulator Device" ] || [ "$SIMULATOR_DEVICE" = "generic/platform=iOS Simulator" ]; then
DESTINATION="generic/platform=iOS Simulator"
else
DESTINATION="platform=iOS Simulator,name=$SIMULATOR_DEVICE"
fi
log_info "Build destination: $DESTINATION"
xcodebuild -workspace "$WORKSPACE" \ xcodebuild -workspace "$WORKSPACE" \
-scheme "$SCHEME" \ -scheme "$SCHEME" \
-configuration "$CONFIG" \ -configuration "$CONFIG" \
-sdk "$SDK" \ -sdk "$SDK" \
-destination "platform=iOS Simulator,name=$SIMULATOR_DEVICE" \ -destination "$DESTINATION" \
-derivedDataPath build/derivedData \ -derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY='' \ CODE_SIGN_IDENTITY='' \
CODE_SIGNING_REQUIRED=NO \ CODE_SIGNING_REQUIRED=NO \