Loading...
Loading...
Manages iOS Simulator devices and tests app behavior using xcrun simctl. Covers device lifecycle (create, boot, shutdown, erase, delete), app install and launch, push notification simulation, location simulation, permission grants via privacy subcommand, deep link testing via openurl, status bar overrides, screenshot and video recording, log streaming with os_log filtering, get_app_container paths, and #if targetEnvironment(simulator) compile-time checks. Use when creating or managing simulator devices, testing push notifications without APNs, simulating GPS locations, granting or resetting privacy permissions, capturing screenshots or screen recordings from the command line, streaming device logs, debugging simulator boot failures, troubleshooting CoreSimulator issues, or checking simulator hardware limitations.
npx skill4agent add dpearson2699/swift-ios-skills ios-simulatorxcrun simctl# List all available simulators grouped by runtime
xcrun simctl list devices available
# List installed runtimes
xcrun simctl list runtimes
# List only booted devices
xcrun simctl list devices booted
# JSON output for scripting
xcrun simctl list -j devices availablejq# Find available device types and runtimes
xcrun simctl list devicetypes
xcrun simctl list runtimes
# Create a device — returns the new UDID
xcrun simctl create "My Test Phone" "iPhone 16 Pro" "com.apple.CoreSimulator.SimRuntime.iOS-18-4"simctl list devicetypessimctl list runtimessimctl list# Boot a specific device
xcrun simctl boot <UDID>
# Shutdown a running device
xcrun simctl shutdown <UDID>
# Factory reset — wipes all data, keeps the device
xcrun simctl erase <UDID>
# Delete a specific device
xcrun simctl delete <UDID>
# Delete all devices not available in the current Xcode
xcrun simctl delete unavailable
# Shutdown everything
xcrun simctl shutdown allbootedxcrun simctl shutdown bootedbooted# Build for simulator first
xcodebuild build \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 16 Pro' \
-derivedDataPath build/
# Install the .app bundle
xcrun simctl install booted build/Build/Products/Debug-iphonesimulator/MyApp.app.app.ipa# Launch by bundle ID
xcrun simctl launch booted com.example.MyApp
# Launch and stream stdout/stderr to the terminal
xcrun simctl launch --console booted com.example.MyApp
# Pass launch arguments
xcrun simctl launch booted com.example.MyApp --reset-onboarding -AppleLanguages "(fr)"
# Terminate a running app
xcrun simctl terminate booted com.example.MyApp--consoleprint()os_log# App bundle location
xcrun simctl get_app_container booted com.example.MyApp app
# Data container (Documents, Library, tmp)
xcrun simctl get_app_container booted com.example.MyApp data
# Shared app group container
xcrun simctl get_app_container booted com.example.MyApp group.com.example.shared{
"aps": {
"alert": {
"title": "New Message",
"body": "You have a new message from Alice"
},
"badge": 3,
"sound": "default"
},
"customKey": "customValue"
}# Send push payload from file
xcrun simctl push booted com.example.MyApp payload.json
# Pipe payload from stdin
echo '{"aps":{"alert":"Quick test"}}' | xcrun simctl push booted com.example.MyApp -# Set a fixed coordinate (latitude, longitude)
xcrun simctl location booted set 37.3349,-122.0090
# List available predefined scenarios
xcrun simctl location booted list
# Run a predefined scenario
xcrun simctl location booted run "City Run"
# Clear the simulated location
xcrun simctl location booted clearrun# Grant a permission
xcrun simctl privacy booted grant photos com.example.MyApp
# Revoke a permission
xcrun simctl privacy booted revoke microphone com.example.MyApp
# Reset all permissions for the app
xcrun simctl privacy booted reset all com.example.MyAppphotosmicrophonecontactscalendarreminderslocationlocation-alwaysmotionsiri# Open a URL (triggers universal links or custom URL schemes)
xcrun simctl openurl booted "https://example.com/product/123"
# Custom URL scheme
xcrun simctl openurl booted "myapp://settings/notifications"apple-app-site-association# Set a clean status bar for screenshots
xcrun simctl status_bar booted override \
--time "9:41" \
--batteryState charged \
--batteryLevel 100 \
--cellularMode active \
--cellularBars 4 \
--wifiBars 3 \
--operatorName ""
# Clear all overrides
xcrun simctl status_bar booted clear# Capture a screenshot
xcrun simctl io booted screenshot screenshot.png
# Record video (press Ctrl+C to stop)
xcrun simctl io booted recordVideo recording.mov
# Screenshot with specific display mask
xcrun simctl io booted screenshot --mask black screenshot.png--maskignoredalphablackalphablackalphablack# Stream all logs at debug level and above
xcrun simctl spawn booted log stream --level debug
# Filter by subsystem
xcrun simctl spawn booted log stream --level debug \
--predicate 'subsystem == "com.example.app"'
# Filter by subsystem and category
xcrun simctl spawn booted log stream --level debug \
--predicate 'subsystem == "com.example.app" AND category == "networking"'
# Filter by process name
xcrun simctl spawn booted log stream \
--predicate 'process == "MyApp"'import os
let networkLogger = Logger(subsystem: "com.example.app", category: "networking")
let uiLogger = Logger(subsystem: "com.example.app", category: "ui")
func fetchData() async throws -> Data {
networkLogger.debug("Starting request to /api/data")
let (data, response) = try await URLSession.shared.data(from: url)
networkLogger.info("Received \(data.count) bytes, status: \((response as? HTTPURLResponse)?.statusCode ?? 0)")
return data
}xcrun simctl spawn booted log stream --level debug \
--predicate 'subsystem == "com.example.app" AND category == "networking"'#if targetEnvironment(simulator)func registerForPush() {
#if targetEnvironment(simulator)
logger.info("Skipping APNs registration — running in Simulator")
#else
UIApplication.shared.registerForRemoteNotifications()
#endif
}var isSimulator: Bool {
ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != nil
}#if targetEnvironment(simulator)| Capability | Simulator Support |
|---|---|
| APNs push delivery | No — use |
| Metal GPU family parity | Partial — host GPU, not device GPU; some shaders differ |
| Camera hardware | No — use photo library injection or mock |
| Microphone | No hardware mic — audio input is routed from Mac microphone |
| Secure Enclave | No — |
| App Attest (DCAppAttestService) | No — |
| DockKit motor control | No — no physical accessory connection |
| Accelerometer / Gyroscope | No real sensors — use |
| Barometer | No |
| NFC (Core NFC) | No |
| Bluetooth (Core Bluetooth) | No — use a real device for BLE testing |
| CarPlay hardware | No — use the separate CarPlay Simulator companion app |
| Face ID / Touch ID hardware | No hardware — use Features > Face ID / Touch ID menu in Simulator |
| Cellular network conditions | No — use Network Link Conditioner on Mac |
# WRONG — hardcoded UDID
xcrun simctl boot "A1B2C3D4-E5F6-7890-ABCD-EF1234567890"
# CORRECT — look up by name and runtime
UDID=$(xcrun simctl list -j devices available | \
jq -r '.devices["com.apple.CoreSimulator.SimRuntime.iOS-18-4"][] | select(.name == "iPhone 16 Pro") | .udid')
xcrun simctl boot "$UDID"
# CORRECT — use "booted" when one simulator is running
xcrun simctl install booted MyApp.appsimctl installsimctl launch# WRONG — device is not booted
xcrun simctl install <UDID> MyApp.app # fails
# CORRECT — boot first, then install
xcrun simctl boot <UDID>
xcrun simctl install <UDID> MyApp.app
xcrun simctl launch <UDID> com.example.MyApp# WRONG — CI script creates and boots but never cleans up
xcrun simctl create "CI Phone" "iPhone 16 Pro" "com.apple.CoreSimulator.SimRuntime.iOS-18-4"
xcrun simctl boot "$UDID"
# ... tests run, pipeline exits ...
# CORRECT — always clean up in CI teardown
cleanup() {
xcrun simctl shutdown all
xcrun simctl delete "$UDID"
}
trap cleanup EXITsimctl push# WRONG — only testing with simctl, shipping without real device testing
xcrun simctl push booted com.example.MyApp payload.json
# "Push works!" — no, it only proves the app handles the payload
# CORRECT — use simctl for development iteration, then verify end-to-end on a real device
# 1. simctl push during development for fast iteration
# 2. Real device + APNs sandbox for integration testing before releaseboot# WRONG — retry loop on a stuck device
xcrun simctl boot "$UDID" # "Unable to boot device in current state: Booting"
xcrun simctl boot "$UDID" # same error, forever
# CORRECT — shut down, erase, and retry
xcrun simctl shutdown "$UDID"
xcrun simctl erase "$UDID"
xcrun simctl boot "$UDID"
# If that fails, reset CoreSimulator entirely
xcrun simctl shutdown all
xcrun simctl erase all
# Last resort: rm -rf ~/Library/Developer/CoreSimulator/Cachesbootedsimctl push#if targetEnvironment(simulator)