I can build using the Xcode command line tools, is there any way I can actually run the application using them? (E.g. the equivalent to pressing Cmd+R in Xcode)
Type this in terminal:
open -a Simulator.app
First decide what device you want to use:
xcrun simctl list
This will give you a list of devices:
-- iOS 9.0 --
iPhone 4s (56632E02-650E-4C24-AAF4-5557FB1B8EB2) (Shutdown)
iPhone 5 (ACD4DB7B-9FC9-49D5-B06B-BA5D5E2F5165) (Shutdown)
iPhone 5s (A8358B76-AD67-4571-9EB7-FFF4D0AC029E) (Shutdown)
iPhone 6 (1D46E980-C127-4814-A1E2-5BE47F6A15ED) (Shutdown)
iPhone 6 Plus (FD9F726E-453A-4A4C-9460-A6C332AB140B) (Shutdown)
Choose the ID (eg. FD9F726E-453A-4A4C-9460-A6C332AB140B) you want (you can create your own device using xcrun simctl create if you want).
Boot the simulator with that device (replacing YOUR-DEVICE-ID with the ID)
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID <YOUR-DEVICE-ID>
Now you should be able to use simctl to install and launch commands.
xcrun simctl install <YOUR-DEVICE-ID> <PATH-TO-APPLICATION-BUNDLE>
xcrun simctl launch <YOUR-DEVICE-ID> <BUNDLE-ID-OF-APP-BUNDLE>
xcrun simctl help for more details. Note that booting a device using simctl does not currently (Xcode 7.2) allow you to do anything else with that device such as launch or install applications. You need to launch the device in the simulator to actually do anything interesting. Also, you cannot delete a device that is in use by the simulator, so you will have to quit/kill the simulator before attempting to delete anything.
open -a simulator
it worked for me
This is the answer you are looking for:
Open terminal
xcrun simctl list
Get udid of the device you want to launch
Paste this in the terminal
open -a Simulator --args -CurrentDeviceUDID 0566AC33-9B91-2DR2-B5BB-C916D3BA8MD3
Open your terminal and paste this code:
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
Use xcrun simctl list to get a list of simulators and their UDIDs.
Then open a specific simulator using xcrun simctl boot <UDIDs>
open /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app/
One of the best solution :
Launch iOS simulator from Terminal by providing name of the device
xcrun simctl boot $(xcrun simctl list devices | grep -m 1 'iPhone 12
Pro' |grep -E -o -i '([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})')
This cmd will seamlessly launch the ios simulator for 'iPhone 12 Pro' device
# Update
In the new Xcode update, supported simulators are from iPhone 8 onwards
summing-up
open -a Simulator && xcrun simctl boot 'iPhone 8 Plus'
Related
Is there a way to launch an app on the iOS simulator from the command line, like
simctl launch <app-package>
or something like that?
To install your app:
xcrun simctl install booted
To launch the app:
xcrun simctl launch booted
Hope this helps.
http://cl.ly/image/2K1H000s170l
Please refer to my screenshot. That's a manual way to set default device in iOS simulator. Can anyone tell me how to do that from command line? Many thanks!
I need that as part of my Jenkins project setup. Thanks a lot!
You can use xcrun to open your device
xcrun instruments -w "iPhone 6 (8.4 Simulator)"
If you want to know all devices installed
xcrun instruments -s
If you need to build and install some app use.
xcodebuild -sdk iphonesimulator8.4 -arch i386 install DSTROOT=~/YourApp
xcrun simctl install booted ~/YourApp/Applications/YourApp.app
You can choose the device that is booted when the simulator launches by passing it on the command line. See Xcode 6 - Launch simulator from command line
Yes as mentioned this is a duplicate.
But to answer your question,
You can use the instruments to launch the simulator of your choice. For Ex:
xcrun instruments -w "iPhone 6 (8.2 Simulator)"
"From the screen shot it seems like you are already on iOS 8. "
I created a basic hello world WatchKit app, and it runs fine on the simulator via XCode 6.3 Beta. However, when I try to deploy the app to the simulator via simctl, results aren't as pleasant. Here's what I tried:
boot&launch sim
xcrun instruments -w "iPhone 6 (8.3 Simulator)"
install app
xcrun simctl install "iPhone 6" com.test.foo.app
xcrun simctl install "iPhone 6" com.test.foo\ WatchKit\ Extension.appex/
xcrun simctl install "iPhone 6" com.test.foo\ WatchKit\ App.app/
When I try to run any of the apps, either from the simulator or by using simctl launch, the main app just crashes.
launch app via simctl
xcrun simctl launch "iPhone 6" com.test.foo
xcrun simctl launch "iPhone 6" com.test.foo\ WatchKit\ App
I'm assuming I shouldn't use simctl install for the WatchKit pieces, as separate app icons are created unlike when running from XCode. Digging into the simulator's system logs, it appears that when I run from XCode the main app is installed first, and the WatchKit pieces are installed as plugins vs separate apps. Not sure how to achieve this from command line, but there must be a way. Nothing documented that I can find, so maybe someone on the inside can help?
OK, got this worked out.
Deploying and Launching WatchKit apps via command line
So, all of the needed WatchKit resources are contained within the main app's bundle. Only need one install command, and then one launch command to launch the WatchKit app. The big gotcha was that app identifiers on the device are not the same as the generic bundle identifier.
boot&launch sim
xcrun instruments -w "iPhone 6 (8.3 Simulator)"
install app (after you build it)
xcrun simctl install "iPhone 6" com.test.foo.app
launch watchkit app (notice the identifier!)
xcrun simctl launch "iPhone 6" com.test.com-test-foo.watchkitapp
I have an automation running in the iOS Simulator that I have to remove before another run. How do I remove the app from the iOS Simulator from the command line?
For each simulator device directory (located at ~/Library/Developer/CoreSimulator/Devices/*), I
tried to delete ./data/Containers/Bundle/Application/ and ./data/Containers/Data/Application/.
Even when I tried to delete the app by long pressing the app in the Simulator (the app becomes jiggly) and click on the X button, the user defaults were not being cleared. I want the app state to be 100% clean.
I found a good solution to solve this problem.
With Xcode 6.1, to uninstall an app, use the following command:
xcrun simctl uninstall booted com.example.apple-samplecode.UICatalog
where com.example.apple-samplecode.UICatalog is the bundle identifier of the application you wish to uninstall.
One approach that we found for deleting user defaults is to delete all files in the ./data/Library/Preferences/* in addition to deleting application and data directories.
However, in Xcode 6, the command xcrun has new subcommand called simctl that allows me to manage iOS Simulator including resetting the simulator, and installing the application.
The solution that I came up with is to use the command
xcrun simctl erase [device ID]
Example
If xcrun simctl list(†) returns
9DDA0CFE-7CEC-40B6-A343-1EC01F282B22 (active, disconnected)
Watch: Apple Watch Series 2 - 42mm (88474523-163E-4021-B591-2AECBFA26997) (Shutdown)
Phone: iPhone 7 Plus (5785E680-15CD-42D3-82AB-597286A270C5) (Shutdown)
then run these 2 commands
xcrun simctl erase 88474523-163E-4021-B591-2AECBFA26997
xcrun simctl erase 5785E680-15CD-42D3-82AB-597286A270C5
(†) The device ID can be obtained from running
xcrun simctl list
This will reset the simulator (equivalent to iOS Simulator > Reset Contents and Settings... menu item).
With Xcode 6.0.1 (Build 6A317), there is either a bug or a change in behavior where when you uninstall an application, user defaults are not removed.
Usage: simctl [--noxpc] [--set <set path>] <subcommand> ... | help [subcommand]
Command line utility to control the iOS Simulator
For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.
Subcommands:
create Create a new device.
delete Delete a device.
erase Erase a device's contents and settings.
boot Boot a device.
shutdown Shutdown a device.
rename Rename a device.
getenv Print an environment variable from a running device.
openurl Open a URL in a device.
addphoto Add a photo to the photo library of a device.
install Install an app on a device.
uninstall Uninstall an app from a device.
launch Launch an application by identifier on a device.
spawn Spawn a process on a device.
list List available devices, device types, or runtimes.
notify_post Post a darwin notification on a device.
icloud_sync Trigger iCloud sync on a device.
help Prints the usage for a given subcommand.
Reset all Content & Settings in a single command
Quit iPhone Simulator
In Terminal, run:
xcrun simctl erase all
This will reset content and settings of all the simulators for the active version of Xcode (the one referenced by xcode-select -p).
xcrun simctl uninstall simulatorIdentifier appBundleId
I want to launch iPhone simulator from command line.
until now I have been using the below command
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator -SimulateDevice
-SimulateDevice is used to launch a specific device type
Now with Xcode 6 the path and the app has been changed to
/Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app/Contents/MacOS/iOS Simulator
but sadly -SimulateDevice option is not working now. I can launch the simulator, but dont have an option to specify which one to launch
Anyone found any alternatives for this with Xcode 6?
Found a way to achieve what I wanted.
Apple has introduced an interesting tool with Xcode 6!
simctl
simclt allows you to control the simulator that are running.
run xcrun simctl to get the list of available subcommands. Lots of new options to play around with.
Now to do what I wanted, here is the command to launch the simulator:
xcrun instruments -w "iPhone 5 (8.0 Simulator)"
-w is to provide a device type and to get the list of available devices.
Just execute this:
xcrun instruments -s
After launching the simulator you can control it using simctl
To install your app:
xcrun simctl install booted <app path>
To launch the app:
xcrun simctl launch booted <app identifier>
With Xcode 6, if you want to have the iOS Simulator.app boot a specific device when it launches, you can run this from the command line:
open -a "iOS Simulator" --args -CurrentDeviceUDID <DEVICE UDID>
where you can figure out the UDID of the device you want to boot from:
xcrun simctl list
With Xcode 7, the application was renamed Simulator.app, so you should update the above accordingly to:
open -a Simulator --args -CurrentDeviceUDID <DEVICE UDID>
For xcode 7:
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID <DeviceUDID>
Get your simulator udid's from xcrun simctl list
To launch a simulator with a specific device booted I´m using list devices subcommand to get the list of all devices available
$ xcrun simctl list devices
== Devices ==
-- iOS 11.2 --
iPhone 5s (E3B6EA43-C805-49C2-9502-A44A465D8DF2) (Shutdown)
iPhone 6 (801E9E11-CA86-473A-9879-4B0742B827FB) (Shutdown)
iPhone 6 Plus (24013349-1A6F-489C-9A68-ABB00EBB4BBF) (Shutdown)
iPhone 6s (1A594D75-146C-4BEA-A250-1FADE7886114) (Shutdown)
iPhone 6s Plus (C2730FA0-11CB-49C9-A087-CB3C1BF1CC3D) (Shutdown)
iPhone 7 (F58B3749-3276-49E5-81C8-EBA1AEA7B242) (Shutdown)
iPhone 7 Plus (98167D8C-8F27-404C-AB02-588D9AAFD071) (Shutdown)
iPhone 8 (96322368-F763-4E0A-8576-ADE9F678211F) (Shutdown)
iPhone 8 Plus (E916D1EE-B67B-4C01-B3F5-C5C80CC4CDF8) (Shutdown)
iPhone SE (ABEFEDDF-7A7C-4B94-9E91-E065170FA47F) (Shutdown)
iPhone X (84DAB7AB-3CA2-4F5B-8C4E-A5B54CA15C31) (Shutdown)
iPad Air (DCD8CF4B-2C9F-4BA1-952A-ACB9CAD0A84D) (Shutdown)
iPad Air 2 (A47C9A05-233F-450F-9A39-318258E9ADEA) (Shutdown)
iPad (5th generation) (819C058E-64AC-4E73-8F41-2C0F919F8B56) (Booted)
this command will output a list of available devices with its UDIDs and statuses
Then I launch the simulator app specifying a device with the -CurrentDeviceUDID option
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID <DEVICE-UDID>
NOTE: replace the with a valid UDID from the list.
For example, if we want to launch the simulator with an Ipad (% generation booted):
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID 84DAB7AB-3CA2-4F5B-8C4E-A5B54CA15C31
UPDATE 23/05/2018
With Xcode 9.3 CurrentDevice UDID option is not working for me, as a workaround, I have to use simctl to boot the device in the simulator before open it.
xcrun simctl boot 2BF01FC0-7E29-4AF1-ADD1-886DF129A9A9
open -a Simulator
You can create, erase, delete, boot, shutdown and upgrade simulators using simctl.
$ xcrun simctl create
Usage: simctl create <name> <device type id> <runtime id>
$ xcrun simctl delete
Usage: simctl delete <device> [... <device n>] | unavailable
To get the list of valid device types and runtimes
xcrun simctl list devicetypes
xcrun simctl list runtimes
To boot a simulator:
xcrun simctl boot "iPhone X"
It will boot as a headless mode.
To make the simulator visible:
open -a Simulator
xcrun simctl boot is simpler than xcrun instruments -w. instruments requires the full device name.
You can specify the hardware and iOS version with -w flag. The format is
instruments -w "simulator-version"
For eg:
instruments -w "iPhone Retina (3.5-inch) - Simulator - iOS 7.1".
You will get the available hardvare-iOS combinations by using the instruments -w help command.
Verified in Xcode 9.4.1
Device list in a REALLY NICE FORMAT:
~/Library/Developer/CoreSimulator/Devices/device_set.plist
Root
DefaultDevices
com.apple.CoreSimulator.SimRuntime.iOS-8-4
com.apple.CoreSimulator.SimDeviceType.iPad-Retina : AB335FAF-E3E3-4AE9-A0AF-D1C6AEB5FBD4
Then you want to run (open) your Simulator app and make sure that a new instance of the app is launched.
The app is here:
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
And the format you'd use is like this:
open -n -a <SimulatorPath> --args -CurrentDeviceUDID <SimDeviceTypeUDID>
So, if I wanted to launch the Simulator above, I'd do this.
open -n -a /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID AB335FAF-E3E3-4AE9-A0AF-D1C6AEB5FBD4
Hot damn! I just tested it and it works on Mac OS 10.11.6. Now the next trick is telling the Simulator to open our installed app. I'm not there yet. Hope this helps. Thanks to https://stackoverflow.com/users/726106/jeremy-huddleston-sequoia for his detailed explanation.
Run this command. The app will be restarted followed by changes. No need to rebuild it again.
ios-sim "launch" "/Library/WebServer/Documents/testapp/build/iphone/build/Debug-iphonesimulator/test.app" "--devicetypeid" "iPad-2" "--exit";
For devicetypeid list:
ios-sim showdevicetypes
Anyone having this issue, this command will open the ios simulator from command prompt
open -a simulator