2

Possible Duplicate:
User Agent string for IPhone 4S

We currently need to dial down certain animations and effects in our web app for the iPhone 4. They all work fine on the 4s so we would like to toggle the effects based on the phone model! Is there any reliable way of telling which phone model is being used? I believe I may be able to parse the user agent string but not 100% comfortable doing that and would only use it as a last resort!

We would like to detect this both in our mobile web app and our phonegap app.

Community
  • 1
  • 1
Tristan
  • 3,845
  • 5
  • 35
  • 58

2 Answers2

0

Your question seems to be a possible duplicate of this one:

Auto detect mobile browser (via user-agent?)

That being said, the accepted answer there suggested:

Reading the User-Agent header will do the trick.

There are some lists out there of known mobile user agents so you don't need to start from scratch. What I did when I had to is to build a database of known user agents and store unknowns as they are detected for revision and then manually figure out what they are. This last thing might be overkill in some cases.

If you want to do it at Apache level, you can create a script which periodically generates a set of rewrite rules checking the user agent (or just once and forget about new user agents, or once a month, whatever suits your case), like

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} (OneMobileUserAgent|AnotherMobileUserAgent|...)
RewriteRule (.*) mobile/$1
which would move, for example, requests to http://domain/index.html to http://domain/mobile/index.html

Additionally, the link in the linked-StackOverflow-accepted answer is broken. However, you can follow this one (which is up to date):

http://www.enterpriseios.com/wiki/UserAgent

Additional References: What is the iPhone 4 user-agent?

Community
  • 1
  • 1
jrd1
  • 10,358
  • 4
  • 34
  • 51
0

PhoneGap exposes something other than the UA string in a device object: http://docs.phonegap.com/en/1.0.0/phonegap_device_device.md.html

The reason UA string sniffing is usually sniffed at is that it has historically been used as an unreliable method of feature-inference, and seeing as what we want in this context is an arbitrary esoteric indicator from which to infer general device performance, the use-case seems genuine — inasmuch as performance indicators have no general standard to be 'feature-detected' as such.

Having said that, I've been looking for years for a performance testing framework (without massive overhead) to determine how much flashiness I want my apps to give… Any answers that speak of this gratefully appreciated by-the-by!

Barney
  • 16,181
  • 5
  • 62
  • 76