iOS Simulator not refreshing with Cordova (PhoneGap)? Read this.

About a month or two ago I noticed something odd with my Cordova tests. I'd fire off a call to the iOS simulator by doing cordova emulate ios. The first time, it worked fine. But as I edited I noticed something odd. Subsequent calls to the emulator would end up in a blank screen in the emulator. If I watched carefully, I'd see my app load for a split second before going black.

Apparently, this is a bug with ios-sim, the command line tool used to talk to the simulator. If you know to check out the GitHub repo for it you will see a tip suggesting this command to fix it: killall launchd_sim

This works like a charm, and since I normally just "edit, alt-tab to terminal, click up, enter" in my dev cycle, I just switched my command to this: killall launchd_sim && cordova emulate ios

Archived Comments

Comment 1 by Shazron posted on 6/20/2014 at 10:15 PM

Hopefully this will be baked in soon... https://issues.apache.org/j...

Comment 2 by Shazron posted on 6/20/2014 at 10:17 PM

You could do this in a before_emulate hook also, for now.

Comment 3 by Raymond Camden posted on 6/20/2014 at 10:18 PM

Shaz, thanks for filing a bug for this. I thought there was one already.

Query - how do yo use before_emulate hooks? This is something I've never used before.

Comment 4 by Shazron posted on 6/20/2014 at 10:42 PM

More info here: https://github.com/apache/c...

Add a hooks folder in your project root, and put the script there.

Comment 5 by Raymond Camden posted on 6/20/2014 at 10:51 PM

As a side note to folks (not related to Shaz's comments above):

I believe one side affect of this killall command is that Safari can't "see" the simulator anymore. What I mean is - when I use Safari Remote debugging and relaunch the app, the simulator is not available in the dropdown under Develop. If I kill Safari and restart it, it is available.

Shaz, any comment on that? If the Cordova CLI does add this in, that could be a possible negative side effect.

Comment 6 by Raymond Camden posted on 6/20/2014 at 10:55 PM

Shaz: Cool, the script works great and is less to type. It would be cool if the --copy-from command for making new projects also had a way to 'seed' hooks too.

Comment 7 by Shazron posted on 6/20/2014 at 10:57 PM

Ouch. Never considered that. To add that into consideration we obviously can't do a killall, and find an alternative. Unfortunately it's an either or situation right now.

In better news, in Xcode 6 it appears ios-sim may finally be obsolete (who knows for sure yet):
https://github.com/phonegap...

Comment 8 by Goy J- posted on 6/27/2014 at 12:38 PM

If I may troll a little: why Safari? This is simply the new IE6!

Comment 9 by Raymond Camden posted on 6/27/2014 at 5:55 PM

Only Safari can "talk" to the device like this. (Well, you can use other tools like Weinre too.)

Comment 10 by Raymond Camden posted on 9/5/2014 at 11:10 PM

For folks curious, the killall will also break GapDebug if you are using that for debugging.