Reputation: 3710
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)
Upvotes: 192
Views: 215835
Reputation: 5293
open terminal on your mac and run this command
open -a simulator
Upvotes: 1
Reputation: 1569
You can Replace version:
npx react-native run-ios --simulator='iPhone 13'
Upvotes: -1
Reputation: 81
As promised, wrote a tiny shell script to launch the XCode Simulator from the command line. Takes the advice from this thread and builds a user prompt around xcrun simctl list
and xcrun simctl boot
.
Quickstart
位 run-ios-sim
Enter phone model (e.g., iPhone 13 mini):
iphone 13
Choose a device type:
1 iPhone 13 Pro
2 iPhone 13 Pro Max
3 iPhone 13 mini
4 iPhone 13
Pass argument directly
位 run-ios-sim iphone 13 mini
Choose a device type:
1 iPhone 13 mini
1
iPhone 13 mini already booted
General usage
位 run-ios-sim -h
Run iOS simulator from the command line.
USAGE
./run-ios-sim [device_type] (e.g., "iPhone 13 mini")
OPTIONS
-h --help Show this help message.
-l --list List available device types.
-i Install script to ~/.local/bin (then call as `run-ios-sim`).
Happy to turn into a proper repo if there's enough interest 馃
Upvotes: 0
Reputation: 31
Here is a handy command to build the project and then run it in the terminal:
xcodebuild -scheme <scheme_name> -destination <destination_name> build && xcrun simctl launch booted <bundle_identifier>
<scheme_name>
- the name of the specific schema, e.g. "MyApp (Dev Environment)"
<destination_name>
- the name of the simulator on which to run. For example "name=iPhone 14 Pro"
<bundle_identifier>
- bundle of your project. Example: com.johnne.myapp
Execution result:
The final command with the data above will look like this:
xcodebuild -scheme "MyApp (Dev Environment)" -destination "name=iPhone 14 Pro" build && xcrun simctl launch booted com.johnne.myapp
Upvotes: 3
Reputation: 921
One of the best solution :
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})')
Upvotes: 6
Reputation: 1157
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
Upvotes: 74
Reputation: 314
Use xcrun simctl list
to get a list of simulators and their UDIDs.
Then open a specific simulator using xcrun simctl boot <UDIDs>
Upvotes: 21
Reputation: 3690
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.
Upvotes: 232
Reputation: 451
Open your terminal and paste this code:
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
Upvotes: 34
Reputation: 962
open /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app/
Upvotes: 9