- Tips & Tricks: изменяем User Agent в iPhone
- User agent iOS iPhone in Firefox
- What is the iPad user agent?
- 15 Answers 15
- What HTTP User-Agent does my iOS program advertise itself as?
- 3 Answers 3
- How can I determine the iOS version with iOS user-agent strings?
- 2 Answers 2
- Not the answer you’re looking for? Browse other questions tagged ios or ask your own question.
- Related
- Hot Network Questions
- Subscribe to RSS
Tips & Tricks: изменяем User Agent в iPhone
Как известно, User Agent необходим для «идентификации» пользователя, а конкретнее, для определения, каким клиентом или через какое устройство заходит пользователь к вам на сайт. В зависимости от этого, можно «подставлять» необходимый контент (данные, разметку). Это актуально в последнее время по причине большого роста мобильных устройств.
В продолжении темы iPhone Dev Tips & Tricks расскажу о том, как поменять User Agent на «iPhone».
Для того, чтобы получить некий контент, который чувствительный к User Agent (в моем конкретном случае я хочу получить XML файл), необходимо выполнить следующий код:
NSURL *url = [[NSURL alloc] initWithString:@»http://domain.com/SomeXml.xml»];
NSHTTPURLResponse *response;
NSError *error;
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setValue:@»Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)» forHTTPHeaderField:@»User-Agent»];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
Как видите, для решения задачи необходимо воспользоваться setValue:forHTTPHeaderField для вашего запроса (NSMutableURLRequest).
В моей конкретной задаче я использовал NSData, так как мне необходимо было использовать полученный XML для NSXMLParser:
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
NSLog(@»XML is downloaded.»);
Источник
User agent iOS iPhone in Firefox
When you display user agent (Request.UserAgent) in Firefox on iPhone, it is:
Mozilla/5.0 (iPhone; CPU OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/23.0 Mobile/15E148 Safari/605.1.15
It produced an error on page
This page contains the following errors: error on line 306 at column 16: xmlParseEntityRef: no name Below is a rendering of the page up to the first error.
Uncaught DOMException: Failed to set the ‘innerHTML’ property on ‘Element’: The provided markup is invalid XML, and therefore cannot be inserted into an XML document.
The word ‘iPhone‘ is missing between ‘CPU OS‘ compare to Chrome or Edge. If you change it to (by adding ‘iPhone’ between ‘CPU OS’ which will become ‘CPU iPhone OS‘):
Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/23.0 Mobile/15E148 Safari/605.1.15
Request.UserAgent in Chrome returns:
Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/23.0 Mobile/15E148 Safari/605.1.15
or Request.UserAgent in Edge returns:
Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/23.0 Mobile/15E148 Safari/605.1.15
Steps to reproduce: Use user agent ‘Mozilla/5.0 (iPhone; CPU OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/23.0 Mobile/15E148 Safari/605.1.15’ in Chrome.
Источник
What is the iPad user agent?
From what I gather, the iPad is using iPhone OS, but with a different screen resolution from the iPhone and iPod touch. So many sites may have to change their user agent detection to adapt to the iPad.
So, can anyone with access to the iPad or the iPad SDK give us the user-agent string?
15 Answers 15
Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10
(almost 10 years later. )
From iOS 13 the iPad’s user agent has changed to Mac OS, for example:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15
From the simulator, in iPad mode:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9 (this is for 3.2 beta 1)
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 (this is for 3.2 beta 3)
and in iPhone mode:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g
I don’t know how reliable the simulator is, but it seems you can’t detect whether the device is iPad just from the user-agent string.
(Note: I’m on Snow Leopard which the User Agent string for Safari is
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10
From a real device:
Mozilla/5.0 (iPad; U; CPU OS OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10
It’s worth noting that when running in web-app mode (using the apple-mobile-web-app-capable meta tag) the user agent changes from:
Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B405 Safari/531.21.10
Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405
iPad 2 under 4.3.5:
Mozilla/5.0 (iPad; U; CPU OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8L1 Safari/6533.18.5
Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; da-dk) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5
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
It seems to be general consensus that every mobile apple device, iphone, ipad, or ipod uses a user agent that contains both ‘Mobile’ and ‘Safari’.
However, using the latest SDK (4.0.1) and reading the user agent on my rails server (using request.env[«HTTP_USER_AGENT»] ), we never get the ‘Safari’ part.
No matter whether the request is being made from the simulator or a real device, debug or release, it always looks something like this:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; de-de) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7D11″
Just no ‘Safari’. 🙁 So we have to use the ‘iPhone’ part to be sure. That is something apple does not recommend doing.
From iOS 13, can not find ‘iPad’, i use this js current-device, it work.
From Simulator 3.2 final:
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/7B367 Safari/531.21.10
Safari on iPad user agent string in iPhone OS 3.2 SDK beta 3:
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
I think it is worth mentioning that you don’t generally need to use the whole agent string, unless perhaps you find a reason where you need to tailor the website to a specific model.
You can check for iPhone, iPad and iPod in the agent string and cover all your bases.
Since Apple VERY HELPFULLY changed their userAgent strings in iOS, you can’t use a regex for ipad/iphone reliably anymore.
Источник
What HTTP User-Agent does my iOS program advertise itself as?
I’ve written an app for my podcast, Otaku no Podcast. In various parts of the app, I use NSURLConnection (fetch RSS feeds), UIWebView (display website content), AVPlayer (play MP3 audio files off our CDN), and MPMoviePlayerViewController (play video files off our CDN). Now, since all of these make HTTP requests of some sort, I’m assuming that they will advertise themselves with the standard iPhone User-agent string. (if my assumption is incorrect please let me know) This means that, based on reading my log files, I have no way of telling which of my visitors is coming in via plain old mobile Safari, vs. using my app.
Is there a way of changing the User-Agent to one of my own? I found this question on SO that describes how to do this with NSURL but I can’t find any information about any of the above classes that I am using.
3 Answers 3
Your original assumption is partly incorrect- A custom User-agent string is used for NSURLRequests from your app. In my testing, the string is
However, some requests from UIWebView use this user-agent string
presumably so that websites can optimise their HTML for the device even if it’s not MobileSafari.
According to this blog post, you may be able to set a pseudo-global User-Agent string (pseudo in that I’m not sure which other classes outside of UIWebView use it).
Here is the class method to add to your main controller (or app delegate) :
According to the comments on that post, «we can’t modify it later» is a bit of an overstatement: you can modify the UserAgent value later, but you have to release and re- alloc any UIWebView s (and I presume NSURLConnection s if they use it too) for the changes to take effect.
Источник
How can I determine the iOS version with iOS user-agent strings?
I have a list of iOS User-Agent strings for approximately 50 different iPhone’s and 30 different iPad’s. I want to know if user-agent strings like Apple-iPad4C5/1202.410, Apple-iPhone4C1/1202.466 etc. can be used to determine the current iOS version running on these devices.
2 Answers 2
My iPhone 6 running iOS 8.2 has this user agent string:
Mozilla/5.0 (iPhone; CPU iPhone OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12D508 Safari/600.1.4
You can see iPhone OS 8_2 within that string. This is the OS version. You can parse that out.
Apple has documented the format of the Safari User-Agent string in the Safari Web Content Guide. You can look at the examples there to see how the User-Agent embeds the iOS version number. Examples include CPU iOS 2_0 and CPU OS 3_2 .
Note, however, that third-party browsers (any app that uses a UIWebView , really, which includes many popular apps) can and often do customize the User-Agent.
Not the answer you’re looking for? Browse other questions tagged ios or ask your own question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.12.7.40929
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник