Cordova: start specific iOS emulator image Cordova: start specific iOS emulator image ios ios

Cordova: start specific iOS emulator image


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

$ cordova emulate ios --listAvailable 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


As say csantanapr you can use:

cordova emulate ios --target="iPhone-4s"

but, in this case cordova (or PhoneGap or other) project will be launched on iPhone 4s simulator with iOS version 7.0.3.

If you want launch project on same simulator, but with other version iOS (7.1 or 8.0, if it versions exist in your system)?

Of corse, you can do like say cobberboy:

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

But you can improve --target option of cordova run command.

At first you must ensure what target iOS version available on your system.

For it use answer of cobberboy:

$ ios-sim showdevicetypes

Then you need to open the file your_project_dir/platforms/ios/cordova/lib/run.js and find lines of code like below:

// validate target device for ios-sim// Valid values for "--target" (case sensitive):var validTargets = ['iPhone-4s', 'iPhone-5', 'iPhone-5s', 'iPhone-6-Plus', 'iPhone-6',    'iPad-2', 'iPad-Retina', 'iPad-Air', 'Resizable-iPhone', 'Resizable-iPad'];

For use iPhone-4s, 7.1 (or some other) simple add it to array validTargets.

var validTargets = ['iPhone-4s', 'iPhone-4s, 7.1', 'iPhone-5', 'iPhone-5s', 'iPhone-6-Plus', 'iPhone-6',    'iPad-2', 'iPad-Retina', 'iPad-Air', 'Resizable-iPhone', 'Resizable-iPad'];

And in

cordova emulate ios --target="iPhone-4s, 7.1"

your --target="iPhone-4s, 7.1" will be valid.

And function deployToSim of run.js:

function deployToSim(appPath, target) {// Select target device for emulator. Default is 'iPhone-6'if (!target) {    target = 'iPhone-6';    console.log('No target specified for emulator. Deploying to ' + target + ' simulator');}var logPath = path.join(cordovaPath, 'console.log');var simArgs = ['launch', appPath,    '--devicetypeid', 'com.apple.CoreSimulator.SimDeviceType.' + target,    // We need to redirect simulator output here to use cordova/log command    // TODO: Is there any other way to get emulator's output to use in log command?    '--stderr', logPath, '--stdout', logPath,    '--exit'];return spawn('ios-sim', simArgs);}

convert iPhone-4s, 7.1 to valid argument com.apple.CoreSimulator.SimDeviceType.iPhone-4s, 7.1 for ios-sim.


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 showdevicetypescom.apple.CoreSimulator.SimDeviceType.iPhone-4s, 7.1com.apple.CoreSimulator.SimDeviceType.iPhone-5, 7.1com.apple.CoreSimulator.SimDeviceType.iPhone-5s, 7.1com.apple.CoreSimulator.SimDeviceType.iPad-2, 7.1com.apple.CoreSimulator.SimDeviceType.iPad-Retina, 7.1com.apple.CoreSimulator.SimDeviceType.iPad-Air, 7.1com.apple.CoreSimulator.SimDeviceType.iPhone-4s, 8.0com.apple.CoreSimulator.SimDeviceType.iPhone-5, 8.0com.apple.CoreSimulator.SimDeviceType.iPhone-5s, 8.0com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus, 8.0com.apple.CoreSimulator.SimDeviceType.iPhone-6, 8.0com.apple.CoreSimulator.SimDeviceType.iPad-2, 8.0com.apple.CoreSimulator.SimDeviceType.iPad-Retina, 8.0com.apple.CoreSimulator.SimDeviceType.iPad-Air, 8.0com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone, 8.0com.apple.CoreSimulator.SimDeviceType.Resizable-iPad, 8.0