Cordova: start specific iOS emulator image

前端 未结 10 2297
暗喜
暗喜 2020-12-07 07:07

I\'m developing a cross-platform mobile app using Cordova, focussing mainly on iOS in the development stage.

For my development process it would be ideal if I could

相关标签:
10条回答
  • 2020-12-07 07:42

    To find out what are the simulator images available you can use to list them

    $ cordova emulate ios --list
    Available iOS Virtual Devices:
        iPhone-4s, 9.3
        iPhone-5, 9.3
        iPhone-5s, 9.3
        iPhone-6, 9.3
        iPhone-6-Plus, 9.3
        iPhone-6s, 9.3
        iPhone-6s-Plus, 9.3
        iPad-2, 9.3
        iPad-Retina, 9.3
        iPad-Air, 9.3
        iPad-Air-2, 9.3
        iPad-Pro, 9.3
    

    Then use one of the simulator names in the --target parameter:

    cordova emulate ios --target="iPhone-4s, 9.3"
    cordova emulate ios --target="iPad-Air-2, 9.3"
    cordova emulate ios --target="iPhone-6s, 9.3"
    cordova emulate ios --target="iPhone-6-Plus, 9.3"
    

    Important Quit the simulator before launching a different target simulator (On Menu bar select Simulator->Quit)

    Take into account that you may need to quit the iOS simulator via menu to switch from 3.5 to 4 inch iPhone.

    dynamic list is available in platforms/ios/cordova/lib/list-emulator-images

    0 讨论(0)
  • 2020-12-07 07:43

    Don't include version number

    cordova run ios --target="iPhone-6s"
    
    0 讨论(0)
  • 2020-12-07 07:48

    @Birja's answer is working right now but the run command he used finally is still wrong so here the right answer:

    To list all the devices available in simulator cordova run ios --list

    It will result in something like this:

    Available ios devices:
    Available ios virtual devices:
    Apple-TV-1080p, tvOS 12.2
    Apple-Watch-Series-2-38mm, watchOS 5.2
    iPhone-5s, 12.2
    iPhone-6, 12.2
    iPad-Air-2, 12.2
    iPad--5th-generation-, 12.2
    iPad-Pro--9-7-inch-, 12.2
    iPad-Pro, 12.2
    iPad-Pro--12-9-inch---2nd-generation-, 12.2
    iPad-Pro--10-5-inch-, 12.2
    iPad--6th-generation-, 12.2
    iPad-Pro--11-inch-, 12.2
    iPad-Pro--12-9-inch---3rd-generation-, 12.2
    

    cordova run ios --target "iPad-Pro, 12.2" Use any target from the above. To run in simulator.

    0 讨论(0)
  • 2020-12-07 07:49

    TL;DR

    You can start a specific emulator and choose your ios version by directly using ios-sim.

    export appname="./platforms/ios/build/emulator/Hello World.app"
    ios-sim launch "$appname" --devicetypeid "com.apple.CoreSimulator.SimDeviceType.iPad-2, 8.0" --stderr ./platforms/ios/cordova/console.log --stdout ./platforms/ios/cordova/console.log
    

    Details

    When I ran this:

    cordova emulate ios --target="iPad"
    

    and looked at the processes running, I saw this (on a single line):

    ios-sim launch ./platforms/ios/build/emulator/HelloWorld.app 
            --stderr ./platforms/ios/cordova/console.log 
            --stdout ./platforms/ios/cordova/console.log 
            --family ipad 
            --exit
    

    Investigating further into ios-sim, it looks like there are some more specific options, particularly:

    --devicetypeid <device type>    The id of the device type that should be simulated (Xcode6+). Use 'showdevicetypes' to list devices.
      e.g "com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone6, 8.0"
    

    So I did as it suggested and ran ios-sim with a "showdevicetypes" argument and got this:

    $ ios-sim showdevicetypes
    com.apple.CoreSimulator.SimDeviceType.iPhone-4s, 7.1
    com.apple.CoreSimulator.SimDeviceType.iPhone-5, 7.1
    com.apple.CoreSimulator.SimDeviceType.iPhone-5s, 7.1
    com.apple.CoreSimulator.SimDeviceType.iPad-2, 7.1
    com.apple.CoreSimulator.SimDeviceType.iPad-Retina, 7.1
    com.apple.CoreSimulator.SimDeviceType.iPad-Air, 7.1
    com.apple.CoreSimulator.SimDeviceType.iPhone-4s, 8.0
    com.apple.CoreSimulator.SimDeviceType.iPhone-5, 8.0
    com.apple.CoreSimulator.SimDeviceType.iPhone-5s, 8.0
    com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus, 8.0
    com.apple.CoreSimulator.SimDeviceType.iPhone-6, 8.0
    com.apple.CoreSimulator.SimDeviceType.iPad-2, 8.0
    com.apple.CoreSimulator.SimDeviceType.iPad-Retina, 8.0
    com.apple.CoreSimulator.SimDeviceType.iPad-Air, 8.0
    com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone, 8.0
    com.apple.CoreSimulator.SimDeviceType.Resizable-iPad, 8.0
    
    0 讨论(0)
提交回复
热议问题