Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

iphone - Cordova: start specific iOS emulator image

I'm developing a cross-platform mobile app using Cordova, focussing mainly on iOS in the development stage.

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

$cordova run --debug --emulator iOS

This works fine, and results in an iOS-simulator running my app in a simulated iPhone 4 Retina with iOS 7.0.3

Besides this simulated device, I would also like to test on (for instance) an iPad. I have these emulation images installed, and I can start my app in them manually in Xcode. Also, the command list-emulator-images (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 thing is: I can't seem to figure out how to start the emulator in anything other than the default (which appears to be the iPhone Retina (4-inch) emulation image). The relevant output of cordova help gives the following information:

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

I've tried things like the following:

cordova run --debug --emulator=iPad iOS

And many variations thereof, but no luck. Every time it starts in the same emulator.

The documentation for the command-line tool doesn't offer any information in this regard, and an extensive Google-search also failed to turn up anything. Am I missing something trivial? Or am I trying to do something weird? I really hope someone here has experience with this, and can provide some answers.

Thanks very much in advance!

edit: forgot to mention explicitly; I'm doing all this on a Mac. As mentioned earlier, running the app in different emulators/simulators in Xcode works fine.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To find out what are the simulator images available you can use to 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 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...