Emulate on iPad directly?


#1

Is it possible to tell Ionic to start the iPad simulator directly instead of the iPhone simulator?

Currently I execute ionic emulate ios which starts the iPhone simulator and I have to change the device manually every time.

I’ve seen there is a --family param which can be passed to cordova’s emulate script.
But if I execute ionic emulate ios --family ipad, still the iPhone simulator is opened.

What I’m doing wrong here?


#2

You’re not doing anything wrong. The Ionic-CLI tool uses cordova under the hood, and the Cordova-CLI uses ios-sim under the hood by running the /platforms/ios/cordova/run shell script.

If you look inside that script, you’ll notice that it exposes the --target switch which maps to --family for ios-sim.

A look inside the code for cordova emulate shows that it concatenates additional command line options before invoking the above mentioned script.

That means that running cordova emulate ios --target=ipad is what you were looking for.

Cheers.


#3

A quick look at the Ionic-CLI code shows that it doesn’t pass additional options given to ionic emulate on to cordova emulate, so that means that ionic emulate ios --target=ipad won’t work, but that’s a quick fix.

I might submit a PR if I don’t forget or someone else doesn’t beat me to it, but I’ve been building my Ionic apps using the Yeoman generator and grunt emulate:ios:--target=ipad does the trick for me :smile:


#4

Hi Diego!

Thanks for your response!!

As I’m fairly new to the whole AngularJS world, can you give me a quick example of how your solution looks like using Yeoman?


#5

Absolutely @marbetschar! Yeoman is a scaffolding tool for modern web applications. The generator I built gives you a sophisticated build system (Grunt.js right now, but plan to add Gulp support) for both local development in a browser and packaging your assets for distribution.

It wraps the cordova CLI so you can use grunt for everything.

If you want to learn more, take a peak at the documentation here https://github.com/diegonetto/generator-ionic

Cheers,
DN


#6

Hi Diego!

Thanks for pointing me into the right direction!

I’ve finally found some time to wrap my head around. I’m using also grunt for building but as a beginner also using Yeoman seemed a bit complicated. Because I’ve got still to learn a lot in my current environment.

Nevertheless emulation does work right now directly on the iPad. This is what I came up with:

Gruntfile.coffee

device = if grunt.option 'device' then grunt.option 'device' else 'ipad'

grunt.registerTask 'emulate',() ->
    grunt.task.run [
        'exec:emulate'
    ]

grunt.initConfig
    exec:
        emulate:
            command: 'cordova emulate ios --target='+device

And now I’m able to simply execute the following line in the CLI to let the magic happen:

grunt emulate --device=ipad

#7

If you want to emulate right to iPad or any device through cordova, you can pass that in the --target flag

cordova emulate ios --target="iPhone"
cordova emulate ios --target="iPad"
cordova emulate ios --target="iPad (Retina)"
cordova emulate ios --target="iPhone (Retina 3.5-inch)"
cordova emulate ios --target="iPhone (Retina 4-inch)"

#8

Hi mhartington!
Yeah, you’re right. But I’ve got some more things going on through Grunt to get the App ready - so I need the tasky solution.

I just thought to post the key parts I came up with, so others may use this as a reference if needed.


#9

it works with cordova, but nut when running ionic emulate


#10

Hmm, just ran

ionic emulate ios --target="iPad"

and it booted up the iPad simulator. What command did you use?


#11

this works for me as well, however

ionic emulate ios --target="iPhone (Retina 4-inch)"

does not. The error is listed as

/bin/sh: -c: line 0: syntax error near unexpected token `('

Anyone have a suggestion for this?


#12

hmm, odd I’m getting this error using ionic as well, but not cordova emulate


#13

This will probably help you guys:

Make sure to use the exact device name as a target and it will work with both cordova and ionic cli

Get the exact names by running $ ./platforms/ios/cordova/lib/list-emulator-images


#14

Hello Mhartington
I try with this command but is no t working, can you help me?

MacBook-Pro-de-dev01:unimedicos_app itmixin10$ cordova emulate ios --target="iPad (Retina)"

Running command: /Users/itmixin10/www/itmixin/unimedicos_app/hooks/after_prepare/010_add_platform_class.js /Users/itmixin10/www/itmixin/unimedicos_app
add to body class: platform-ios
Running command: /Users/itmixin10/www/itmixin/unimedicos_app/platforms/ios/cordova/run --emulator "–target=iPad (Retina)"
iPad (Retina) is not a valid target for emulator
Error: /Users/itmixin10/www/itmixin/unimedicos_app/platforms/ios/cordova/run: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:766:16)
at Process.ChildProcess._handle.onexit (child_process.js:833:5)
MacBook-Pro-de-dev01:unimedicos_app itmixin10$


#15

In the latest release of cordova, the targets have changed.

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


#16

Already running thank you very much


#17

Does this mean that we cannot emulate on iPad Pro at all?