|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +# Configuration - modify these values as needed |
| 4 | +DEVICE_TYPE="iPhone 16" |
| 5 | +IOS_VERSION="18.5" |
| 6 | + |
3 | 7 | start_simulator() { |
4 | 8 | echo "Starting iOS Simulator..." |
5 | | - xcrun simctl boot "iPhone 16" || echo "Simulator already booted" |
| 9 | + echo "Looking for: $DEVICE_TYPE with iOS $IOS_VERSION" |
| 10 | + |
| 11 | + # List available simulators to debug |
| 12 | + echo "Available simulators:" |
| 13 | + xcrun simctl list devices available |
| 14 | + |
| 15 | + # Try to find the specified device with the specified iOS version |
| 16 | + DEVICE_ID=$(xcrun simctl list devices available | grep -A1 "iOS $IOS_VERSION" | grep "$DEVICE_TYPE " | head -1 | grep -o "[A-F0-9-]{36}") |
| 17 | + |
| 18 | + if [ -z "$DEVICE_ID" ]; then |
| 19 | + echo "No $DEVICE_TYPE with iOS $IOS_VERSION found. Trying to create one..." |
| 20 | + # Try to create the device with the specified iOS version |
| 21 | + IOS_RUNTIME="com.apple.CoreSimulator.SimRuntime.iOS-${IOS_VERSION//./-}" |
| 22 | + DEVICE_TYPE_ID="com.apple.CoreSimulator.SimDeviceType.${DEVICE_TYPE// /-}" |
| 23 | + DEVICE_ID=$(xcrun simctl create "${DEVICE_TYPE} Test" "$DEVICE_TYPE_ID" "$IOS_RUNTIME" 2>/dev/null) |
| 24 | + |
| 25 | + if [ -z "$DEVICE_ID" ]; then |
| 26 | + echo "Failed to create $DEVICE_TYPE with iOS $IOS_VERSION. Using any available $DEVICE_TYPE." |
| 27 | + DEVICE_ID=$(xcrun simctl list devices available | grep "$DEVICE_TYPE " | head -1 | grep -o "[A-F0-9-]{36}") |
| 28 | + fi |
| 29 | + fi |
| 30 | + |
| 31 | + if [ -z "$DEVICE_ID" ]; then |
| 32 | + echo "Error: Could not find or create any $DEVICE_TYPE device" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + |
| 36 | + echo "Using device ID: $DEVICE_ID" |
| 37 | + export SIMULATOR_DEVICE_ID="$DEVICE_ID" |
| 38 | + |
| 39 | + # Boot the device |
| 40 | + xcrun simctl boot "$DEVICE_ID" || echo "Simulator already booted" |
6 | 41 | sleep 30 |
7 | | - xcrun simctl bootstatus || echo "Simulator booted successfully" |
| 42 | + xcrun simctl bootstatus "$DEVICE_ID" || echo "Simulator booted successfully" |
8 | 43 | } |
9 | 44 |
|
10 | 45 | set_status_bar() { |
11 | 46 | echo "Setting status bar on iOS Simulator..." |
12 | | - xcrun simctl status_bar "iPhone 16" override --time "11:01" --wifiBars 3 --cellularBars 4 --batteryState charged --batteryLevel 100 |
| 47 | + if [ -z "$SIMULATOR_DEVICE_ID" ]; then |
| 48 | + echo "Error: SIMULATOR_DEVICE_ID not set" |
| 49 | + return 1 |
| 50 | + fi |
| 51 | + xcrun simctl status_bar "$SIMULATOR_DEVICE_ID" override --time "11:01" --wifiBars 3 --cellularBars 4 --batteryState charged --batteryLevel 100 |
13 | 52 | } |
14 | 53 |
|
15 | 54 | install_ios_app() { |
16 | 55 | echo "Installing iOS app on simulator..." |
17 | | - xcrun simctl install booted ios-app/Debug-iphonesimulator/NativeTemplate.app |
| 56 | + if [ -z "$SIMULATOR_DEVICE_ID" ]; then |
| 57 | + echo "Error: SIMULATOR_DEVICE_ID not set" |
| 58 | + return 1 |
| 59 | + fi |
| 60 | + xcrun simctl install "$SIMULATOR_DEVICE_ID" ios-app/Debug-iphonesimulator/NativeTemplate.app |
18 | 61 | } |
19 | 62 |
|
20 | 63 | verify_installed_app() { |
21 | 64 | echo "Verifying installed app..." |
22 | | - xcrun simctl get_app_container booted com.mendix.native.template |
| 65 | + if [ -z "$SIMULATOR_DEVICE_ID" ]; then |
| 66 | + echo "Error: SIMULATOR_DEVICE_ID not set" |
| 67 | + return 1 |
| 68 | + fi |
| 69 | + xcrun simctl get_app_container "$SIMULATOR_DEVICE_ID" com.mendix.native.template |
23 | 70 | } |
24 | 71 |
|
25 | 72 | start_simulator |
|
0 commit comments