$npx -y skills add dpearson2699/swift-ios-skills --skill ios-simulatorManages iOS Simulator devices and app tests with xcrun simctl: lifecycle, install/launch, push and location simulation, privacy permissions, deep links, status-bar overrides, screenshots/video, log streaming, app containers, and targetEnvironment(simulator). Use when scripting Si
| 1 | # iOS Simulator |
| 2 | |
| 3 | Load [the simctl command reference](references/simctl-commands.md) when you need |
| 4 | complete command tables, JSON parsing, privacy/status-bar values, Logger filter |
| 5 | setup, or boot recovery commands. |
| 6 | |
| 7 | ## Contents |
| 8 | |
| 9 | - [Device Lifecycle](#device-lifecycle) |
| 10 | - [App Install and Launch](#app-install-and-launch) |
| 11 | - [Testing Workflows](#testing-workflows) |
| 12 | - [Screenshot and Video Recording](#screenshot-and-video-recording) |
| 13 | - [Log Streaming](#log-streaming) |
| 14 | - [Compile-Time Simulator Detection](#compile-time-simulator-detection) |
| 15 | - [Simulator Limitations](#simulator-limitations) |
| 16 | - [Common Mistakes](#common-mistakes) |
| 17 | - [Review Checklist](#review-checklist) |
| 18 | - [References](#references) |
| 19 | |
| 20 | ## Device Lifecycle |
| 21 | |
| 22 | ### Listing Devices and Runtimes |
| 23 | |
| 24 | ```bash |
| 25 | # List all available simulators grouped by runtime |
| 26 | xcrun simctl list devices available |
| 27 | |
| 28 | # List installed runtimes |
| 29 | xcrun simctl list runtimes |
| 30 | |
| 31 | # List only booted devices |
| 32 | xcrun simctl list devices booted |
| 33 | |
| 34 | # JSON output for scripting |
| 35 | xcrun simctl list -j devices available |
| 36 | ``` |
| 37 | |
| 38 | Parse JSON output to find a specific device programmatically. See [references/simctl-commands.md](references/simctl-commands.md) for `jq` parsing examples. |
| 39 | |
| 40 | ### Creating a Device |
| 41 | |
| 42 | ```bash |
| 43 | # Find available device types and runtimes |
| 44 | xcrun simctl list devicetypes |
| 45 | xcrun simctl list runtimes |
| 46 | |
| 47 | # Create a device — returns the new UDID |
| 48 | xcrun simctl create "My Test Phone" "iPhone 16 Pro" "com.apple.CoreSimulator.SimRuntime.iOS-18-4" |
| 49 | ``` |
| 50 | |
| 51 | Device types and runtime identifiers in examples throughout this skill are illustrative. Run `simctl list devicetypes` and `simctl list runtimes` to find the identifiers available on your system. |
| 52 | |
| 53 | Use the returned UDID for subsequent commands. |
| 54 | |
| 55 | ### Boot, Shutdown, Erase, Delete |
| 56 | |
| 57 | ```bash |
| 58 | # Boot a specific device |
| 59 | xcrun simctl boot <UDID> |
| 60 | |
| 61 | # Boot if needed and wait until the device is ready |
| 62 | xcrun simctl bootstatus <UDID> -b |
| 63 | |
| 64 | # Shutdown a running device |
| 65 | xcrun simctl shutdown <UDID> |
| 66 | |
| 67 | # Factory reset — wipes all data, keeps the device |
| 68 | xcrun simctl erase <UDID> |
| 69 | |
| 70 | # Delete a specific device |
| 71 | xcrun simctl delete <UDID> |
| 72 | |
| 73 | # Delete all devices not available in the current Xcode |
| 74 | xcrun simctl delete unavailable |
| 75 | |
| 76 | # Shutdown everything |
| 77 | xcrun simctl shutdown all |
| 78 | ``` |
| 79 | |
| 80 | Use `booted` as a UDID shorthand when exactly one simulator is running: |
| 81 | |
| 82 | ```bash |
| 83 | xcrun simctl shutdown booted |
| 84 | ``` |
| 85 | |
| 86 | If multiple simulators are booted, `booted` picks one of them non-deterministically. Prefer explicit UDIDs when running parallel simulators. |
| 87 | |
| 88 | In scripts and CI, `xcrun simctl bootstatus <UDID> -b` is the canonical |
| 89 | boot-and-readiness gate before install, launch, push, or location commands. |
| 90 | |
| 91 | ## App Install and Launch |
| 92 | |
| 93 | ### Installing an App |
| 94 | |
| 95 | ```bash |
| 96 | # Build for simulator first |
| 97 | xcodebuild build \ |
| 98 | -scheme MyApp \ |
| 99 | -destination 'platform=iOS Simulator,name=iPhone 16 Pro' \ |
| 100 | -derivedDataPath build/ |
| 101 | |
| 102 | # Boot and wait for SpringBoard/services before install |
| 103 | xcrun simctl bootstatus <UDID> -b |
| 104 | |
| 105 | # Install the .app bundle |
| 106 | xcrun simctl install <UDID> build/Build/Products/Debug-iphonesimulator/MyApp.app |
| 107 | ``` |
| 108 | |
| 109 | The path must point to a `.app` directory built for the simulator architecture, not a `.ipa` file. |
| 110 | |
| 111 | ### Launching and Terminating |
| 112 | |
| 113 | ```bash |
| 114 | # Launch by bundle ID |
| 115 | xcrun simctl launch booted com.example.MyApp |
| 116 | |
| 117 | # Launch and stream stdout/stderr to the terminal |
| 118 | xcrun simctl launch --console booted com.example.MyApp |
| 119 | |
| 120 | # Pass launch arguments |
| 121 | xcrun simctl launch booted com.example.MyApp --reset-onboarding -AppleLanguages "(fr)" |
| 122 | |
| 123 | # Terminate a running app |
| 124 | xcrun simctl terminate booted com.example.MyApp |
| 125 | ``` |
| 126 | |
| 127 | `--console` is useful for debugging — it shows `print()` and `os_log` output directly in the terminal. |
| 128 | |
| 129 | ### App Container Paths |
| 130 | |
| 131 | ```bash |
| 132 | # App bundle location |
| 133 | xcrun simctl get_app_container booted com.example.MyApp app |
| 134 | |
| 135 | # Data container (Documents, Library, tmp) |
| 136 | xcrun simctl get_app_container booted com.example.MyApp data |
| 137 | |
| 138 | # Shared app group container |
| 139 | xcrun simctl get_app_container booted com.example.MyApp group.com.example.shared |
| 140 | ``` |
| 141 | |
| 142 | ## Testing Workflows |
| 143 | |
| 144 | ### Push Notification Simulation |
| 145 | |
| 146 | Create a JSON payload file: |
| 147 | |
| 148 | ```json |
| 149 | { |
| 150 | "aps": { |
| 151 | "alert": { |
| 152 | "title": "New Message", |
| 153 | "body": "You have a new message from Alice" |
| 154 | }, |
| 155 | "badge": 3, |
| 156 | "sound": "default" |
| 157 | }, |
| 158 | "customKey": "customValue" |
| 159 | } |
| 160 | ``` |
| 161 | |
| 162 | Send it to the Simulator: |
| 163 | |
| 164 | ```bash |
| 165 | # Send push payload from file |
| 166 | xcrun simctl push booted com.example.MyApp payload.json |
| 167 | |
| 168 | # Pipe payload from stdin |
| 169 | echo '{"aps":{"alert":"Quick test"}}' |