12
votes

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.

3
@Dave DeLong: An example reason would be to disable heavy number-crunching portions of the website on the older phones, which can't handle the load. (That's not the reason in this case, however, but I cannot disclose the reason here :/.)Grant Paul

3 Answers

5
votes

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.

4
votes

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.

-2
votes

Little Benchmark that detects older models. The Benchmark takes 5-30ms so no real problem.

function runBenchmark(){
    var time,
    init = new Date(),
    iterations = 5000;
    while (iterations--) {
        Math.sqrt(iterations*Math.random());
    }
    time = new Date - init;
    return time;
}

function detectIphoneSpeed () {
    if (runBenchmark()<15) {
        return "3gs";
    } else {
        return "3g";
    }
}
var iphoneSpeed = detectIphoneSpeed();