About
To control the Xcode Simulator from the command line, use the xcrun simctl
utility, which offers commands for managing simulators (booting, shutting down, erasing, listing, etc.) and interacting with them.
Some basic commands to control simulator
Here’s a breakdown of key commands and their uses:
- Listing Simulators:
- Command:
xcrun simctl list
- Purpose: Displays a list of available simulators, their device types, and operating system versions.
- Command:
- Booting a Simulator:
- Command:
xcrun simctl boot <device_type>
- Purpose: Starts a specific simulator (replace
with the desired device type, e.g., "iPhone 13 Pro").
- Command:
- Shutting Down a Simulator:
- Command:
xcrun simctl shutdown booted
- Purpose: Shuts down all running simulators.
- Command:
- Erasing a Simulator:
- Command:
xcrun simctl erase <simulator_udid>
- Purpose: Resets a simulator to its initial state, deleting all apps and data. You’ll need to find the simulator’s UDID (Unique Device Identifier) first using xcrun simctl list.
- Command:
- Simulating Hardware Controls:
- Command:
xcrun simctl <simulator_udid> <action> <value>
- Purpose: Simulate events like changing language, locale, UI appearance, location, push notifications, background fetch, shake gesture, or device orientation.
- Examples:
xcrun simctl set_language <simulator_udid> en
(set language to English)xcrun simctl set_location <simulator_udid> 37.3323 -122.0312
(set location to San Francisco)xcrun simctl send_push <simulator_udid> <bundle_id>
(send push notification)xcrun simctl shake <simulator_udid>
(simulate shake gesture)
- Command:
- Other Useful Commands:
xcrun simctl help
: Displays a list of all available simctl commands.xcrun simctl listapps <simulator_udid>
: Lists installed apps on a simulator.xcrun simctl install <path_to_ipa> <simulator_udid>
: Installs an app on a simulator.xcrun simctl uninstall <bundle_id> <simulator_udid>
: Uninstalls an app from a simulator.