Cordoba: launch a specific iOS emulator image

I am developing a cross-platform mobile application using Cordova, focusing mainly on iOS at the development stage.

For my development process, it would be ideal if I could launch the Cordova application directly from the command line and load it into the specified emulator. I can do this by running the following in the project root directory:

$cordova run --debug --emulator iOS 

This works great, and as a result, the iOS simulator launches my application in simulated iPhone 4 Retina with iOS 7.0.3

Besides this simulated device, I would also like to test (for example) the iPad. I have these emulation images installed, and I can run the application in them manually in Xcode. In addition, the list-emulator-images command (located in project_dir/platforms/ios/cordova/lib ) gives the following output:

 "iPhone Retina (3.5-inch)" "iPhone Retina (4-inch)" "iPhone Retina (4-inch 64-bit)" "iPhone" "iPad" "iPad Retina" 

However, the fact is that I canโ€™t understand how to start the emulator in something different from the standard one (which looks like an iPhone Retina (4-inch) emulation image). The corresponding cordova help output gives the following information:

 run [--debug|--release] [--device|--emulator|--target=FOO] [PLATFORM] ............................ deploys app on specified platform devices / emulators 

I tried things like:

cordova run --debug --emulator=iPad iOS

And many of its options, but not luck. Every time it runs in the same emulator.

The documentation for the command line tool does not contain any information in this regard, and the extensive Google search also failed to activate something. Am I missing something trivial? Or am I trying to do something weird? I really hope someone has experience with this and can provide some answers.

Thank you very much in advance!

edit: forgot to specify explicitly; I do all this on a Mac. As mentioned earlier, running the application in different emulators / simulators in Xcode works great.

+111
ios iphone cordova
Mar 10 '14 at 20:23
source share
10 answers

To find out which simulator images are available, you can 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 Close the simulator before starting another target simulator (In the menu bar, select Simulator->Quit )

Please note that you may need to exit the iOS simulator through the menu in order to switch from iPhone to 3.5 inches by 4 inches.

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

+323
Mar 11 '14 at 14:50
source share

As csantanapr says , you can use:

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

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

If you want to run a project on the same simulator, but with a different version of iOS (7.1 or 8.0, if it exists on your system)?

From corsa you can make, for example, cobberboy :

launch a special emulator and select the ios version using ios-sim.

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

First you need to make sure that the target version of iOS is available on your system.

To do this, use cobberboy's answer:

 $ ios-sim showdevicetypes 

Then you need to open your_project_dir/platforms/ios/cordova/lib/run.js and find the lines of code, as shown 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']; 

To use iPhone-4s, 7.1 (or some others) just add it to the validTargets array.

 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 the deployToSim run.js function:

 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 output to use in log command? '--stderr', logPath, '--stdout', logPath, '--exit']; return spawn('ios-sim', simArgs); } 

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

+17
Apr 17 '15 at 17:21
source share

TL; DR

You can run a special emulator and select your version of ios 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 

More details

When I ran this:

 cordova emulate ios --target="iPad" 

and looked at the running processes, I saw this (in one 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 

Studying further ios-sim , it seems that there are several more specific options, in particular:

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

So, I did as he suggested, and ran ios-sim with the argument "showdevicetypes" and got the following:

 $ 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 
+10
Oct 19 '14 at 12:46 on
source share

Do not include version number

 cordova run ios --target="iPhone-6s" 
+7
Aug 10 '17 at 17:37 on
source share

Starting with Xcode 8.3.2 ...

The old thread, I know, but it seems that perhaps the answer has changed a bit. Tips from earlier posts in this thread helped, but also read the documentation included in the code, <cordova-project>/platforms/ios/cordova/lib/run.js

Run ./platforms/ios/cordova/lib/list-emulator-images to view the available emulator images. Do not include the version number at the end when the cordova call is launched in the desired emulator.

 cordova run ios --emulator --target="iPad-Air" 

More details

+4
Jun 03 '17 at 8:04 on
source share

I can not comment on the answer above due to my low reputation, but a list of goals is available from:

 start-emulator 

under

 your platform/ios/cordova/lib/ 

Having said that, I can't get the ipad retina emulator to work ...

+3
Apr 19 '14 at 10:32
source share

Fastest list of devices: $ instruments -s devices

Just use the device name without version.

+3
Nov 04 '17 at 14:29
source share

Launches an iOS simulator with a web request based on an already created build for the Cordova application. To execute this request from the browser, the simulator opens on a Mac with iPhone 8Plus version: http: // hostname: 3000 / cordova / build / [xxxx-buildnumber] / emulate? Target = iPhone-8-Plus

0
Nov 06 '18 at 10:28
source share

Great simulator iphone and ipad

  1. Cordova Run IOS --list

  2. Cordova imitate iOS --target "iPhone-7"

0
Feb 12 '19 at 9:55
source share

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

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

This 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 of the targets listed above. Run in the simulator.

0
Jun 07 '19 at 4:43
source share



All Articles