What is the best way to distinguish on a server between a request that came from an iPhone through the web browser vs through an iphone with an app written in objective c? What differences do I look for in the user agent string?
Asked
Active
Viewed 2.0k times
3 Answers
35
It seems that iPhone Apps using the UIWebKit HTTP request component have user agent string like the following
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; fr-fr) AppleWebKit/532.9 (KHTML, like Gecko) Mobile/8A306
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; fr-fr) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7D11
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; fr-fr) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7E18
While Safari on iPhone has mostly the same string but ending with " Safari/XXX"
However, it is also possible to change the user agent of UIWebKit then there is no guarantee that you'll grab every iPhone app by proceeding this way.
-
1In addition to "Mobile/XXX" and "Safari/XXX", Chrome for iOS adds a "CriOS/XXX" part to the UA strng. See https://developer.chrome.com/multidevice/user-agent – pau.moreno Apr 24 '14 at 10:39
1
I believe user agents from the Safari app start with "Mozilla", while user agents from apps start with the name of the app.

James J
- 6,428
- 6
- 35
- 45
-4
Indeed the user agent will be different.
in PHP, you can find out with this: $_SERVER['HTTP_USER_AGENT']

jpmartineau
- 67
- 6