how to pick the ios emulator from cordova / ionic command line

CordovaIonic Framework

Cordova Problem Overview


in using the ionic emulate command line (i'm assuming it's the same as cordova phoengap) how do I pick the device - either ipad or iphone tall screen. It always defaults to the 3.5" screen.

Cordova Solutions


Solution 1 - Cordova

With later versions of Ionic and Cordova one can use any of the following commands to list available emulations. The following commands have been tested with Ionic v3.20.0 and Cordova 8.0.0:

ionic cordova emulate --list # List any OS
cordova run --list           # List any OS
cordova run ios --list       # List specific OS

And they yield something like:

Available ios virtual devices:
iPhone-5s, 11.2
iPhone-6, 11.2
iPhone-6-Plus, 11.2
iPhone-6s, 11.2
iPhone-6s-Plus, 11.2
iPhone-7, 11.2
iPhone-7-Plus, 11.2
iPhone-8, 11.2
iPhone-8-Plus, 11.2
iPhone-SE, 11.2
iPhone-X, 11.2
iPad-Air, 11.2
iPad-Air-2, 11.2
iPad--5th-generation-, 11.2
iPad-Pro--9-7-inch-, 11.2
iPad-Pro, 11.2
iPad-Pro--12-9-inch---2nd-generation-, 11.2
iPad-Pro--10-5-inch-, 11.2
Apple-Watch-38mm, watchOS 4.2
Apple-Watch-42mm, watchOS 4.2
Apple-Watch-Series-2-38mm, watchOS 4.2
Apple-Watch-Series-2-42mm, watchOS 4.2
Apple-Watch-Series-3-38mm, watchOS 4.2
Apple-Watch-Series-3-42mm, watchOS 4.2
Apple-TV-1080p, tvOS 11.2

To start the emulator with a specific OS use:

ionic cordova emulate ios --target "iPhone-X"

See also: https://cordova.apache.org/docs/en/latest/reference/cordova-cli/#cordova-run-command

For an older installation of Ionic and Cordova I used the syntax mentioned in RipTheJacker's answer to select the device to emulate, ie:

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

However, to find out what the available emulations are I run this:

ios-sim showdevicetypes

This command will return a list, something like this:

iPhone-4s, 8.4
iPhone-5, 8.4
iPhone-5s, 8.4
iPhone-6-Plus, 8.4
iPhone-6, 8.4
iPad-2, 8.4
iPad-Retina, 8.4
iPad-Air, 8.4
Resizable-iPhone, 8.4
Resizable-iPad, 8.4

Solution 2 - Cordova

cordova emulate ios --target="TARGET"

or

ionic emulate ios --target="TARGET"

Where TARGET is one of: iPad, iPhone, iPad (Retina), iPhone (Retina 3.5-inch), iPhone (Retina 4-inch)

E.g: ionic emulate ios --target="iPhone-5"

Solution 3 - Cordova

May 2018 update

Run

ionic cordova run ios --target="iPhone-X"

You can replace iPhone-X by whatever comes from the list

./platforms/ios/cordova/lib/list-emulator-images

from your project's root folder (as said in Tod Thomson's comment)

For me the list is

iPhone-5s, 11.3
iPhone-6, 11.3
iPhone-6-Plus, 11.3
iPhone-6s, 11.3
iPhone-6s-Plus, 11.3
iPhone-7, 11.3
iPhone-7-Plus, 11.3
iPhone-8, 11.3
iPhone-8-Plus, 11.3
iPhone-SE, 11.3
iPhone-X, 11.3
iPad-Air, 11.3
iPad-Air-2, 11.3
iPad--5th-generation-, 11.3
iPad-Pro--9-7-inch-, 11.3
iPad-Pro, 11.3
iPad-Pro--12-9-inch---2nd-generation-, 11.3
iPad-Pro--10-5-inch-, 11.3
Apple-TV-1080p, tvOS 11.3
Apple-TV-4K-4K, tvOS 11.3
Apple-TV-4K-1080p, tvOS 11.3
Apple-Watch-38mm, watchOS 4.2
Apple-Watch-42mm, watchOS 4.2
Apple-Watch-Series-2-38mm, watchOS 4.2
Apple-Watch-Series-2-42mm, watchOS 4.2
Apple-Watch-Series-3-38mm, watchOS 4.2
Apple-Watch-Series-3-42mm, watchOS 4.2

The os version (ie 11.3) might change depending on the images you downloaded and your XCode version. So if the devices in this list don't work just run the command and get your own list.

Solution 4 - Cordova

I don't know why this answers are not working for me. But what it does is doing the next:

native-run --list

Virtual Devices:

  iPad (5th generation) 12.2 11904882-5E5A-4941-B291-5D38F3B51E98
  iPad (6th generation) 12.2 82079A1A-87C1-47EC-BEC2-69BA97FC440C
  iPad Air 12.2 7E90921D-D166-4CE1-956F-0193EF6E972F
  ...

This brings me the ids of the devices so i can do this next:

ionic cordova run ios --livereload --target "BA4986B3-9102-4250-91BF-7DDF7D7BC60D"

Solution 5 - Cordova

I've been having the same issue since ionic2. Looks as though ionic/cordova ignores ios-sim and assigns it's own at emulation run time, refer to your installed platform eg ios (platforms/ios/cordova/lib/run.js):

To view available simulators run

> ios-sim showdevicetypes

/ 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',
    'iPhone-6s-Plus', 'iPhone-6s', 'iPad-2', 'iPad-Retina', 'iPad-Air', 'iPad-Air-2',
    'iPad-Pro', 'Resizable-iPhone', 'Resizable-iPad'];
if (!(runOptions.device) && runOptions.target && validTargets.indexOf(runOptions.target.split(',')[0]) < 0 ) {
    return Q.reject(runOptions.target + ' is not a valid target for emulator');
}

As long as you run the correct simulator under the list you should be fine:

> ionic emulate ios --target="iPhone-6s-Plus, 10.2"

Solution 6 - Cordova

Some changes are happen on latest version as per June 2020, now --target command not considering device name instead, need to place UDID of target simulator device.

Step 1: ionic cordova run ios --list

Virtual Devices:

[native-run] iPhone 11 Pro Max 13.6 0C6BD29C-7507-XXXX-XXXX-2CE2XXXX [native-run] iPhone 8 13.6 CEAE9A99-703F-XXXX-XXXX-10647A9XXXX

Step 2:

Copy only the UDID of particular device for example "0C6BD29C-7507-XXXX-XXXX-2CE2XXXX"

Step 3:

Run the following command

ionic cordova emulate ios -l --external --target="0C6BD29C-7507-XXXX-XXXX-2CE2XXXX"

Runs successfully as on versions

Ionic:

Ionic CLI : 6.10.0 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.0.7 @angular-devkit/build-angular : 0.803.26 @angular-devkit/schematics : 8.3.26 @angular/cli : 8.3.26 @ionic/angular-toolkit : 2.2.0

Cordova:

Cordova CLI : 9.0.0 ([email protected]) Cordova Platforms : android 8.1.0, ios 5.1.1 Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 22 other plugins)

System:

Android SDK Tools : 26.1.1 (/Users/kushal/Library/Android/sdk) ios-deploy : 1.10.0 ios-sim : 8.0.2 NodeJS : v12.18.0 (/usr/local/bin/node) npm : 6.14.6 OS : macOS Catalina Xcode : Xcode 11.6 Build version 11E708

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMonkeyBonkeyView Question on Stackoverflow
Solution 1 - CordovaJohn PView Answer on Stackoverflow
Solution 2 - CordovaRipTheJackerView Answer on Stackoverflow
Solution 3 - CordovaHugo HView Answer on Stackoverflow
Solution 4 - CordovaDaniel S.View Answer on Stackoverflow
Solution 5 - CordovaRodrigo RubioView Answer on Stackoverflow
Solution 6 - CordovaKushal KulleView Answer on Stackoverflow