Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect iPhone 3G or 3GS (and iPod touch 2G vs iPod touch 3G) in JavaScript

Tags:

iphone

Does anyone know a way to detect the older set of devices:

  • iPod touch 1G
  • iPhone 2G
  • iPhone 3G
  • iPod touch 2G

From the newer set:

  • iPhone 3GS
  • iPod touch 3G
  • iPad
  • iPhone 4

I have found methods to detect the iPhone 4 and the iPad (using screen size). However, is there a way to tell the iPhone 3GS and the iPod touch 3G from the iPod touch 1G and the iPhone 2G?

Requirements:

  • Being hacky is okay! Just make sure it works /all/ of the time.
  • Performance testing is /not/ accurate enough: but if you can get it to work 100% of the time, that'd be fine.

(Example for the iPhone 2G and iPod touch 1G detection, using a "hidden" method: "iPad and iPhone 3G and later support H.264 Baseline profile 3.1. Earlier versions of iPhone support H.264 Baseline profile 3.0." from https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/AudioandVideoTagBasics/AudioandVideoTagBasics.html).

Edit: There is no way I can get around this requirement: there is no alternative solution besides this detection.

like image 735
Grant Paul Avatar asked Jul 16 '10 06:07

Grant Paul


2 Answers

If number crunching would be a discriminator... use it! Just benchmark a small loop (call it BogoMips) and within some 0.5 seconds you know what you are up to.

The hardware and software are defined, the load is pretty much defined (well.. iOS 4 'multitasking'?), so I think it can be very accurate.

edit I only read your remarks on performance testing now; maybe you meant this exactly, maybe you meant to measure page render time. My suggestion is to have a page with only a piece of javascript which then stores the result as a cookie and redirects. Pretty much all circumstances are known then.

like image 200
mvds Avatar answered Oct 06 '22 00:10

mvds


Have you looked into the UserAgent string?

For example, my iPhone 4 returns:

Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7

The Mobile/8A306 is the firmware version (just google for 8a306 iphone

I believe the older versions of the phones cannot run the new versions of the OS. So you might be able to find a set of firmware codes that will only show up on the older versions of the phones. This will at least allow you to detect some of the differences.

The WURFL has some good references and user agent strings and how to detect the device and capabilities based on it. There is a browseable list of them, and they might be able to detect the devices correctly. I don't have access to the older hardware, so I can't confirm it works all the time. You can explore what your device shows up as using: http://www.tera-wurfl.com/explore/ And to look at the various UserAgent strings given back.

like image 39
christophercotton Avatar answered Oct 05 '22 23:10

christophercotton