91

What is the iOS 5.0 user agent string?

Here is the iOS 4.0 user agent: What is the iPhone 4 user-agent?

1
  • 2
    On this SO answer, you can find a generic regular expression to check if a given user agent string is a iOS 5.0 one.
    – Stephan
    Sep 25, 2012 at 11:31

5 Answers 5

151

iPhone:

Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3

iPad:

Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3
1
  • 3
    Correct. From my iPhone: Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3
    – Ben
    Oct 19, 2011 at 18:04
11

This site seems to keep a complete list that's still maintained

iPhone, iPod Touch, and iPad from iOS 2.0 - 5.1.1 (to date).

You do need to assemble the full user-agent string out of the information listed in the page's columns.

2
10

I found a more complete listing at user agent string. BTW, this site has more than just iOS user agent strings. Also, the home page will "break down" the user agent string of your current browser for you.

2
2

fixed my agent string evaluation by scrubbing the string for LOWERCASE "iphone os 5_0" as opposed to "iPhone OS 5_0." now i am properly assigning iOS 5 specific classes to my html, when the uppercase scrub failed.

1
  • 1
    Well, I, personally would detect more than just iPhone, because in the example above you are not rendering iOS 5 specific code to iPads and iPod touch. What you might also want to think about is the fact that the version will increment at some point. My recommendation would probably be apparent to most - detect an apple mobile device first, i.e. iPad/iPod/iPhone and then, if that's the case, parse out the version of... not the iOS but probably the browser, i.e. in this case Version/5.1 would be the indicator. Once you know the version, you would apply your code on "not lower than" condition.
    – hndcrftd
    Oct 21, 2011 at 22:29
1

I use the following to detect different mobile devices, viewport and screen. Works quite well for me, might be helpful to others:

var pixelRatio = window.devicePixelRatio || 1;

var viewport = {
    width: window.innerWidth,
    height: window.innerHeight
};

var screen = {
    width: window.screen.availWidth * pixelRatio,
    height: window.screen.availHeight * pixelRatio
};

var iPhone = /iPhone/i.test(navigator.userAgent);
var iPhone4 = (iPhone && pixelRatio == 2);
var iPhone5 = /iPhone OS 5_0/i.test(navigator.userAgent);
var iPad = /iPad/i.test(navigator.userAgent);
var android = /android/i.test(navigator.userAgent);
var webos = /hpwos/i.test(navigator.userAgent);
var iOS = iPhone || iPad;
var mobile = iOS || android || webos;

window.devicePixelRatio is the ratio between physical pixels and device-independent pixels (dips) on the device. window.devicePixelRatio = physical pixels / dips.

More info here.

1
  • 1
    Thanks for the response, but note that this isn't an efficient way and some device versions will be lost. For example I just checked the user agent on my ancient iPad 1 and it says "...iPad; CPU OS 5_1_1...". None of your variables would have caught that. You would need a regex like var iOS5 = /(iPhone|iPad).*OS 5_.*/i.test(navigator.userAgent); Oct 14, 2012 at 3:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.