We were recently using PhoneGap on an iPad specific JavaScript app (HTML5 in PhoneGap with Drupal data backend FTW!) and ran into a problem with the first gen iPad's RAM capability. For this specific project we just needed to disable some functionality for iPad 1 users, so I (with some objective C help from Chris Trahey) cobbled together a quick iPad version detection plug-in.

Our first idea was browser user agent string detection (like this), right? Simple. Too bad that doesn't actually work. The user agent string ("Mobile/xxxxx") isn't actually consistent. I don't know why, but it just isn't. So in-browser solutions are out. Next we started digging into the PhoneGap API.

PhoneGap core comes with the device API, which is great, but device.name (the most obvious option) for iOS returns the device's custom name. This wasn't useful, since "Hulk" isn't the answer I was looking for. There are ways to get the model name from iOS, but that didn't seem like the best (or even pseudo future proof) way either. I ended up checking for presence of camera to detect iPad 1, and presence of retina display for iPad 3+ and iPhone 4+.

To (hopefully) save some other non-objective-c devs some of the serious headaches I had, I threw it up on Github this morning for public use.

I'm totally open to improving this and making it super useful, so if you have code send me a pull request (I'm a web dev, so I'm guessing my C isn't all that pretty), and ideas are always welcome. Ideas with code are the best though, as we all know.