1

I have an outstanding question that is about the use of the screen size in an non full screen UIWebview to detect an iPhone 5 device in Javascript. I am starting to believe that this is not the way to go.

Right now I am investigating even more ugly hacks to do this. What caught my attention is that the Javascript evaluation on an iPhone 5 is twice as fast as on the iPhone 4. Maybe we could run some calculations and time that. We then could say the device is an iPhone 5 if it completes in < x ms.

Does anybody know of an example of this kind of test? And what calculations could best be benchmarked?

Community
  • 1
  • 1
RickyA
  • 15,465
  • 5
  • 71
  • 95
  • won't completion time also be dependent on network speed? – Joe Jan 07 '13 at 13:45
  • do you have control over the UIWebView? – Diego Torres Jan 07 '13 at 13:46
  • @Joe: Not if it is done in pure javascript. download js -> execute function -> test results. It would however depend on background processes. – RickyA Jan 07 '13 at 13:47
  • @Diego Torres: no unfortunately. – RickyA Jan 07 '13 at 13:47
  • 2
    I hate to be the one to ask this, but why do you want to know the device-type so specifically? This smells like user-agent sniffing and I can't begin to express to you just how bad an idea it really is. – Paul Turner Jan 07 '13 at 13:50
  • 1
    "Right now I am investigating even more ugly hacks to do this" - that's the spirit! – Paul D. Waite Jan 07 '13 at 13:50
  • @Tragedian: Trust me, I want it. The explanation is to long to put in here, but I want to be able to specificly target iPhone 5's. And yes, I am aware every solutions is going to be nasty and prone to error's but as long as the majority of cases are correctly detected I am fine. – RickyA Jan 07 '13 at 14:34

1 Answers1

0

There is no way to reliably determine the device version this way. Some iPhone may be faster than others, and I wouldn't be surprised if a new iPhone 4 can be faster than a heavily used iPhone 5.

However, the iPhone 5 is the only iPhone that supports iOS 6.0.2+. Get the phone's User Agent, and check what OS it's running. Since Apple's a little pushy with their updates, I think this is the most reliable way to check for device versions.

(Not that UA sniffing is reliable, or a good idea to begin with, as UA's are easily faked, but that's a different matter altogether)

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
  • Are they particularly easily faked on the iPhone though? If it's not jailbroken? – Paul D. Waite Jan 07 '13 at 13:51
  • 2
    @PaulD.Waite: I have a free [browser](https://itunes.apple.com/en/app/terra-web-browser-tabs-full/id394704159?mt=8) on my iPad (not jailbroken) that lets me set it's UA. Predefined choices, yes, but a choice of 9, including Firefox, chrome, etc. I'm pretty sure it's just as easy on a iPhone. – Cerbrus Jan 07 '13 at 13:53
  • gotcha, I wasn't sure if that sort of thing was prohibited by the App Store rules. – Paul D. Waite Jan 07 '13 at 14:32
  • @Cerbrus: Well, and here we have an example where the sandbox of the UIWebview works to our advantage: no (easy) UA spoofing. – RickyA Jan 07 '13 at 14:37
  • @Cerbrus: I'll have a look at the UA then, but my gut feeling is that the fail rate will be really high. – RickyA Jan 07 '13 at 14:39
  • @RickyA: I'm kinda curious what the most reliable solution is. Too bad something like "DeviceInfo" isn't sent in HTTP headers. But then again, privacy etc.. – Cerbrus Jan 07 '13 at 14:43
  • Just use UA detection, it's the safest way. See my answer on how to do it. – Timo Ernst Apr 09 '13 at 17:25
  • @valmar: UA detection only (unreliable) detects OS version NOT devices. – RickyA Apr 11 '13 at 08:55