ChatGPT解决这个技术问题 Extra ChatGPT

What is the iOS 5.0 user agent string?

What is the iOS 5.0 user agent string?

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

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.

c
chown

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

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
N
Nate

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.


I started with the site referenced here but it did not have the web-kit build number, which is what Google Analytics displays. I found a more complete list at useragentstring.com/pages/Safari.
I compiled a list with VERY big amount of user-agents. Hope it will help: codereye.com/2014/12/list-of-mobile-user-agents.html
Thanks @Nate, will do so.
A
Andrew Steitz

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.


The user agent string link is broken. :( I think it should point here now: useragentstring.com/pages/useragentstring.php?name=Safari
@LucasMorgan, thanks for the note! I have fixed it in my answer.
G
Geek Devigner

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.


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.
f
fulvio

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.


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);