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

Solution 1:

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 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:

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:

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:

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"