From 977080bc2d974b430af6cd3c7c5fe888ee8d05bc Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Tue, 11 Nov 2025 22:11:23 -0800 Subject: [PATCH] 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 --- .../ios-test-app/scripts/build-and-deploy.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test-apps/ios-test-app/scripts/build-and-deploy.sh b/test-apps/ios-test-app/scripts/build-and-deploy.sh index 7775aeb..eb9a5b1 100755 --- a/test-apps/ios-test-app/scripts/build-and-deploy.sh +++ b/test-apps/ios-test-app/scripts/build-and-deploy.sh @@ -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