views:

540

answers:

2

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 http://developer.apple.com/safari/library/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.

+2  A: 

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.

christophercotton
The iPhone 3G and 3GS can both run iOS 4. That user agent string only tells the firmware version, not the needed device model.
chpwn
(Also, the WURFL website only has definitions for iPhone or iPod touch: nothing again about specific models.)
chpwn
I don't believe the iPod Touch 1st Gen will run OS 4.0. But again, it doesn't give you the exact details you need. Also, if it really is a computational thing, you should put in part of your loop to see how far it is progressing. Easy to see if you have made it as far as you want, and if the device can't keep up, then you can bail or make modifications. Not as nice as knowing up front.
christophercotton
I'm really sad that this non-answer which tells me unrelated information and doesn't answer the question got half my bounty :(.
chpwn
+3  A: 

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.

mvds
That's what I'm thinking I'll do, but my test that I created was only about 95% accurate :/.
chpwn
Don't know what you tried of course, but I would try to target specific cpu features which JS cannot mask. It seems on x86 you can very accurately predict the L1 cache size from within JS, e.g. by accessing a string (semi-)randomly. Increasing string size and measuring 100k access time, I see a big jump at 32kb. On a 3G I cannot see such a clear cut. If you do see one on the 3GS, you have a way to tell them apart. Another one may be to benchmark floating point operations compared to integer ones.
mvds
another way to cut through to benchmarking the raw cpu speed without the JS slowness layer, may be to devise some complex regular expression with a lot of backtracking. Regexps will be handled by some library and probably use optimized C code, which is what you need.
mvds
I'm accepting this answer because it actually addresses my question, unlike the other one. Sorry that you don't get the bounty, mvds.
chpwn
no problem, but thanks anyway. Be sure to share your solution if you manage to find one ;-)
mvds