Having trouble emulating iOS with Cordova/Ionic?

Ok, so this one was a doozie. A few days ago, I got a bit ticked off that whenever I emulated iOS I was getting an iPhone 5 device. I know it’s just a simulation, but I wanted an iPhone 6 or higher to be the default. It’s easy enough to pass a flag to the emulate command to tell it what device/sdk to use (Important note for targeting iOS Emulators in Cordova), but as I have the memory of a kitten, I thought it might be easier to simple delete the older emulators.

So I did that. Because why not? If you’re curious how that’s done - open up XCode, go to Window/Devices.

Then just right click on a device and select delete:

So yeah, I did that, and then a day or so later began getting errors trying to emulate iOS:

Error

You’ll notice that I’m calling out something specific here - the iPhone5 target. For some reason, Cordova was trying to use the iPhone 5 even though I had deleted it. I confirmed this was the issue by opening up the XCode project Cordova had created and I could emulate just fine from there.

Long story short - I filed a bug report (CB-12287) and Cordova contributor and all around kick ass dev Kerri Shotts figured out the problem. Turns out one script has a hard coded call to iPhone 5 while another script was updated to use the ‘last of a list’ of valid emulators. So basically it’s a real bug (and not just something else I did stupid).

Kerri provided a workaround:

cordova emulate ios --buildFlag="-destination platform=iOS Simulator,name=iPhone 7 Plus"

Or do what I did - in the project I’m working on I simply modified the script to use the iPhone 7.

Like This?

If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can also subscribe to the email feed to get notified of new posts.

Want to read more like this?