How can I launch the iOS Simulator from Terminal?

前端 未结 8 681
梦如初夏
梦如初夏 2020-12-07 10:12

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)

8条回答
  •  醉酒成梦
    2020-12-07 11:09

    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 
    

    Now you should be able to use simctl to install and launch commands.

    xcrun simctl install  
    xcrun simctl launch  
    

    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.

提交回复
热议问题