fix(ios): improve simulator auto-detection to use device ID

Enhanced simulator auto-detection for better reliability:

Device ID Support:
- Extracts both device name and UUID from simulator list
- Uses device ID (UUID) for xcodebuild destination when available
- More reliable than device name matching
- Falls back to device name if ID not available

Detection Improvements:
- Better parsing of simulator list output
- Handles edge cases where device name might not match exactly
- Logs both device name and ID for debugging

Fixes:
- Device not found: Using UUID ensures exact device matching
- Auto-detection: More robust extraction of device information
- Build reliability: Device ID is more reliable than name matching

Result: Script should now correctly auto-detect and use available iPhone simulators
This commit is contained in:
Matthew Raymer
2025-11-11 22:11:23 -08:00
parent 302560f12f
commit 977080bc2d

View File

@@ -81,13 +81,17 @@ log_info "Using CocoaPods: $POD_CMD"
if [ -z "$1" ]; then
# Auto-detect first available iPhone simulator
# Extract device name from: " iPhone 17 Pro (UUID) (Status)"
SIMULATOR_DEVICE=$(xcrun simctl list devices available | grep -i "iPhone" | head -1 | sed 's/^[[:space:]]*\([^(]*\).*/\1/' | xargs || echo "")
if [ -z "$SIMULATOR_DEVICE" ]; then
SIMULATOR_LINE=$(xcrun simctl list devices available | grep -i "iPhone" | head -1)
if [ -z "$SIMULATOR_LINE" ]; then
# Fallback to generic simulator
SIMULATOR_DEVICE="generic/platform=iOS Simulator"
log_warn "No iPhone simulators found, using generic destination"
else
log_info "Auto-detected simulator: $SIMULATOR_DEVICE"
# Extract device name (everything before the first parenthesis)
SIMULATOR_DEVICE=$(echo "$SIMULATOR_LINE" | sed 's/^[[:space:]]*\([^(]*\).*/\1/' | xargs)
# Extract device ID (UUID in parentheses)
SIMULATOR_ID=$(echo "$SIMULATOR_LINE" | sed -n 's/.*(\([^)]*\)).*/\1/p' | head -1)
log_info "Auto-detected simulator: $SIMULATOR_DEVICE (ID: $SIMULATOR_ID)"
fi
else
SIMULATOR_DEVICE="$1"
@@ -157,7 +161,12 @@ 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"
elif [ -n "$SIMULATOR_ID" ]; then
# Use device ID for more reliable matching
DESTINATION="platform=iOS Simulator,id=$SIMULATOR_ID"
log_info "Using device ID for destination: $SIMULATOR_ID"
else
# Fallback to device name
DESTINATION="platform=iOS Simulator,name=$SIMULATOR_DEVICE"
fi