Xcode 6 - Launch simulator from command line

前端 未结 8 1183
执念已碎
执念已碎 2020-11-28 00:20

I want to launch iPhone simulator from command line.

until now I have been using the below command

/Applications/Xcode.app/Contents/Developer

8条回答
  •  不知归路
    2020-11-28 00:58

    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 
    

    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   
    
    $ xcrun simctl delete
    Usage: simctl delete  [... ] | unavailable
    

    To get the list of valid device types and runtimes

    xcrun simctl list devicetypes
    
    xcrun simctl list runtimes
    

提交回复
热议问题