User agent iphone 12 mini

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

Источник

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

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.

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.9.40950

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

User Agent in Safari on iPadOS

During authentication flow in Safari, we have a case when in order to satisfy a condition policy, user needs to install the app on his device. Depending on the OS, we ask him to install different applications. Since on iPadOS User Agent in Safari is same as on MacOS Catalina, what is recommened way to distinguish OS on server side?

Safari: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15

Safari: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36

Answers

I have a similar situation as antrix1989 where our webclient determines if a user is browsing via an iPad with JavaScript and alters/restricts the content. We can then market our clients to a subscription on/with our native iOS app. Would be super helpful if the User Agent stated it was iPad OS instead of Mac OS X:

so a regex match could be done to fairly certain determine a user was on iPad.

Hopefully this will change closer to or after the release?

Читайте также:  Как ввести пароль если не работает сенсор айфон

Any update on this? Will the issue be solved before ios13 is released? I’m facing the same issue on iPads.

In our case we use the user agent to detect if the browser belongs to a mobile device.

This is important because on mobile devices we set our web application to listen the touch events such touchstart, touchend, etc, to drag some elements. But currently we cannot subscribe to those events since we cannot detect it is a mobile device.

Somebody in another forum suggested me to verify if Safari browser is not set to show the desktop version of the web site. I’ll check that today. But I think this is still an issue because even if user agent is retrieved as the desktop device, mouse events are not being emulated by safari.

Источник

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

Читайте также:  Apple iphone есть wifi

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.

Источник

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.

Источник

Оцените статью