I have a web page that when viewed from an iOS device displays slightly different content. To detect the device in question the site looks for iPad;, iPod;, or iPhone; in the user agent string.
This works perfectly on Safari on all iOS devices. Testing with Chrome for iOS it works on iPhone and iPad 1, but not iPad 3. The web site is getting the following (unexpected) user-agent string:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.53.11 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10
This seems to be related to the "request desktop site" option in the chrome menu (what would be the wrench icon in desktop chrome). For my site it's disabled and seems to be locked to the desktop rather than mobile site. For other sites, it's enabled and results in a different user-agent string being sent when selected. eg: try http://ifconfig.me/all
So my questions are:
what criteria does Chrome use to decide whether to enable this option
given that Chrome has forced this site to the desktop site, how do I render iOS specific content (in my case a link using a protocol that is handled by my app)
If you'd like to test this yourself, there's a page here that simply reflects the user-agent string.
http://minicompapp.com/Home/UserAgent
The browser will switch between using the two User Agent strings based on whether you are acting as a mobile browser of masquerading as the desktop browser.
User Agent:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-gb)
AppleWebKit/534.46.0 (KHTML, like Gecko)
CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3
User Agent after "Request desktop version":
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3)
AppleWebKit/534.53.11 (KHTML, like Gecko)
Version/5.1.3 Safari/534.53.10
This is only a hint to the web server about who the client is. The browser should render the received web content independently of the User Agent.
Related
I recently notice that approximately 17 % of users with ios device have browser with strange user agent. This user agent like the Safari user agent but with slight modification: it does not contain "Safari/XXXX" string.
Example:
normal user agent of Safari:
Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25
user agent of browser that i talk:
Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d
Can somebody explain me, how it can be? Which browser have this strange user agent?
The shorter user agent comes when an ipad enters "web app" mode. This means that a phone is parsing the html only using webkit, in full screen mode, not within a safari browser window. Thus only the information about CPU version, webkit version, etc is sent along.
http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html
Additional discussion can be found on this very similar post:
ipad user agent changes during use?
I'm trying to load this page in a UIWebView:
http://www.usopenofsurfing.com/on-demand/dvr
It works using Flash on a desktop browser, but has a different implementation when it detects iOS. It works just fine on Mobile Safari, but it's not working in the UIWebView.
Any idea why?
I've looked at the reported User Agents between actual Mobile Safari and the UIWebView.
UIWebView: iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206
Safari: iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3
The javascript which is switching between the flash and the iOS functionality simply looks for the strings ipad, iphone, or ipod:
var deviceAgent = navigator.userAgent.toLowerCase();
var is_iOS = deviceAgent.match(/(iphone|ipod|ipad)/);
So the User Agent should only come into play when choosing between Flash and iOS and that appears to be done properly.
Cookies may be the problem here.
To the best of my understanding, Cookies can not be sent with the first request from a Webview, but can be sent with subsequent requests to the same URL, if and only if, the first request was successful.
This causes problems with authentication services that require cookies to authenticate on the first request to the URL.
Also see this stack article and this apple documentation.
I'm using this piece of code that is working correctly to detect iOS devices when browsing through the Safari browser:
def mobile_user_agent?
#mobile_user_agent ||= ( request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"] [/(Mobile\/.+Safari)/] )
end
But it doesn't detect a user coming to the site through an App's browser on the device. Mainly Twitter.
I believe this is the UA for a twitter user, so how do you accomodate for this (and other Apps as well?)
"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A405"
What i would do is change the regex to something like
/(Mobile\/.+Safari)|(AppleWebKit\/.+Mobile)/
I'm trying to view a users tweets from my app but twitter responses with a webpage saying:
Sorry that page is not supported on mobile at this time
However if i load the same URL with mobile safari i get a nice webpage with all the tweets.
I'm using this URL: http://mobile.twitter.com/SOME_USERNAME/tweets
You can reproduce the error message by visiting the url in safari. If you use safari as developer and you set the user agent to iPhone you'll get the right page.
It seems the webview is sending different headers as User Agent:
Mozilla/5.0 (iPhone Simulator; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176
vs
Mozilla/5.0 (iPhone Simulator; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3
Is there anything i could do about this problem?
Apperently it does work when i remove the /tweets part of the URL.
This is not really the answer to my question but it is the best option as long as nobody comes up with a better answer i'll accept this answer.
Is it possible to get the model information of an iPhone hitting a web page? I've looked at the User Agent, but it doesn't seem to have this information encoded within it. Essentially, I want to do this but from a browser.
They do have different user agent strings. iPhone 4 is
Mozilla/5.0 (iPhone; 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
You can find the complete list here: http://www.zytrax.com/tech/web/mobile_ids.html