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,22 +77,36 @@ fi
log_info "Using CocoaPods: $POD_CMD"
# Get simulator device (default to iPhone 15 Pro)
SIMULATOR_DEVICE="${1:-iPhone 15 Pro}"
log_info "Using simulator: $SIMULATOR_DEVICE"
# Boot simulator
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
log_info "✓ Simulator booted"
# Get simulator device (default to first available iPhone, or user-specified)
if [ -z "$1" ]; then
# Auto-detect first available iPhone simulator
SIMULATOR_DEVICE=$(xcrun simctl list devices available | grep -i "iPhone" | head -1 | sed 's/.*(\(.*\))/\1/' | xargs || echo "")
if [ -z "$SIMULATOR_DEVICE" ]; then
# Fallback to generic simulator
SIMULATOR_DEVICE="Any iOS Simulator Device"
log_warn "No iPhone simulators found, using generic destination"
else
log_warn "Could not boot simulator automatically"
log_info "Opening Simulator app... (you may need to select device manually)"
open -a Simulator
sleep 5
log_info "Auto-detected simulator: $SIMULATOR_DEVICE"
fi
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
log_info "✓ Simulator booted"
else
log_warn "Could not boot simulator automatically"
log_info "Opening Simulator app... (you may need to select device manually)"
open -a Simulator
sleep 5
fi
fi
fi
@@ -120,11 +134,20 @@ SCHEME="App"
CONFIG="Debug"
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" \
-scheme "$SCHEME" \
-configuration "$CONFIG" \
-sdk "$SDK" \
-destination "platform=iOS Simulator,name=$SIMULATOR_DEVICE" \
-destination "$DESTINATION" \
-derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY='' \
CODE_SIGNING_REQUIRED=NO \