Distinguish between iPhone web browser and iPhone app user agent - iphone

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?

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.

I believe user agents from the Safari app start with "Mozilla", while user agents from apps start with the name of the app.

Indeed the user agent will be different.
in PHP, you can find out with this: $_SERVER['HTTP_USER_AGENT']

Related

user agent of iPhone doesn't contain iPhone string

To ensure users use iPhones to access web application, I check user agent in the http request. Some times I found there is no iPhone string in it . the caught user agent is
mozilla/5.0 (macintosh; intel mac os x 10_15_6) applewebkit/605.1.15 (khtml, like gecko) version/14.0 safari/605.1.15
the tag is macintosh not iPhone. As I know , macintosh represent a computer not a mobile.
But the user told me he used iPhone to access system. Did he use a fake iPhone mobile ?

What is the best way to determine iOS 7 Safari user agent?

I'm having a styling issue that only exists in the iOS 7 versions of Safari. I have been unable to determine how to detect if the user is on that device with CSS Media queries or what the exact user agents are for iOS 7 devices.
Any help?
Just try:
navigator.userAgent.match(/(iPad|iPhone);.*CPU.*OS 7_\d/i)
IPhone/iOS7 user agent string looks like this:
Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53

What is iphone's indicator flag for user agent?

What is the indicator flag for iphone default browser's (safari) user agent like IE9 for internet explorer 9 and FF3 for firefox 3 and so on?
Mozilla/5.0 (iPod; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
^^ User-Agent String for iPhone 4 w/ IP4 <-- Indicator Flag
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
^^ User-Agent String for iPad w/ iPad <-- Indicator Flag
Maybe this help you: http://www.zytrax.com/tech/web/browser_ids.htm#safari
I think you can safely use iPhone.
For details see here and here.

What is the user agent of an iPhone that does not have 4.0+?

Can someone give examples?
I know that iPhone 4.2.1 has "4_2" inside the user agent.
What about other models?
Can someone help?
Google is your friend. It's easy to find a definitive list of Safari user agent strings, of which many are Mobile Safari on iPhone. An example pre-iOS 4.0 string is:
Mozilla/5.0 (iPhone; U; CPU OS 3_2
like Mac OS X; en-us)
AppleWebKit/531.21.10 (KHTML, like
Gecko) Version/4.0.4 Mobile/7B334b
Safari/531.21.10
Note the strings "iPhone" and "CPU OS 3_2 like Mac OS X" which tell you it's an iPhone running iOS 3.2.
You are probably really looking for the user agent string of the browser people use on the iPhone (not the phone itself), which is normally Mobile Safari, in combination with the device (iPhone, iPad, etc.) Remember that a user could install other browsers if they wish, and that iOS runs on more devices than just the iPhone (two others, at the moment, and who knows what will happen in the future.) This is a long way of saying, be careful how you do and what you do with your user agent sniffing.

user agent in safari to iphone

I've changed the User Agent in Safari browser to iPhone but nothing happens. Am I misunderstanding the use of this? I'm running Safari in a window environment.
Thanks,
rod.
'nothing happens' means what? What are you expecting? After changing user agent I need to force refresh the webpage, and go to mobile version of website again.
E.g. when with firefox's user-agent, http://m.google.com redirects to another page. But with iPhone's it shows original mobile website. The user agent for iPhone 3 is as follows:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16