I've been playing with PhoneGap a lot recently, in part to prepare Marbles2, but also to bring JS Console to the iPhone as a native app. I've always wanted to create an app that worked on all devices, but getting the launch image correct for each device can be tricky.

How the launch image works on PhoneGap

Basically there's two launch images. Once for the native app and once (manually by PhoneGap) whilst the UIWebView (aka Safari) is loading up. The native one is handled by the app as per the documentation on the Apple developer site, but the overlaid image is hardcoded to 'Default.png'. This is what we'll fix.

Changes to PhoneGapDelegate.m

To get the three devices to work properly, you need to make a change to PhoneGapDelegate.m. Changing the following line†:

Adding the Launch Images

The iPhone 4 image is easy, you call it [email protected] and drag it in to the xcode project. The iPhone 3GS (and below) image is called Default.png and also dragged in to the project (there will probably already be a phonegap default image that you'll overwrite). Finally the iPad image needs to be called Default~ipad.png.

This only works because we've made the change to use initWithImage because it'll automatically detect the device type and add the extension.

One Final Tip

If you notice that when your app loads the launch image jumps, it's because the phonegap UIWebView is (incorrectly) offset by negative 20 pixels - we can fix this too.

Michael Brooks wrote a really elegant little bit of code that fixes the offset in the web view that's also contributing to the launch image jumping.

Add the code from this gist http://gist.github.com/510407 to your *AppDelegate.m (in that if your app is called jsconsole, add the code to jsconsoleAppDelegate.m).

Once that code is in, you'll have your universal phonegap app with launch images all in the appropriate size for the app.

I used this technique for the iOS version of JS Console (though I'm not totally sure it'll get accepted to the itunes store!!!).