Support isIPhone with apple-mobile-web-app-capable meta tag
If your Lift web app sets the <meta name="apple-mobile-web-app-capable" content="yes" /> meta tag, the iPhone browser user agent changes from something like:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5
to
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8C148
This means that isIPhone returns false (with Lift 2.2)
This appears to be a pattern with Apple devices:
http://stackoverflow.com/questions/2153877/what-is-the-ipad-user-agent/3330941#3330941
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5
to
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8C148
This means that isIPhone returns false (with Lift 2.2)
This appears to be a pattern with Apple devices:
http://stackoverflow.com/questions/2153877/what-is-the-ipad-user-agent/3330941#3330941
Leave a comment
on 2011-02-18 15:13 *
By Richard Dallaway
According to Using the Safari User Agent String, Safari Web Content Guide the existing regexp in Req.scala is correct.
The second user agent example in this ticket has no Safari version number. There is no regular expression to help us. From what I can deduce this is because the page is rendered not technically by Safari, but by a component of iOS. I cannot find any definitive statement of this, but there's a hint in Safari HTML Reference, Supported Meta Tags where the authors write: "The default behavior is to use Safari to display web content". The implication is that with the meta tag set, Safari is not used for the rendering of content. An additional clue is in an Apple mailing list discussion from 2008 suggesting that the UIWebView component sends a different user agent string.
I suggest that as Apple do not consider this to be Safari, nor should Lift, but that we document the situation on the Wiki.
From my use-case, I wish to treat these two user agents as the same. As such checking for "iPhone.*Mobile" in the UA is enough, for me, and I do not need a version. But we should be aware that other browsers will come and go, and others will have different use-cases, so it may be wise to make isIPhone pluggable with a user supplied function (for example, just checking for /iPhone/ will match both Safari user agents and the Opera iPhone browser user agent).
Additional Background: The user experience is that when the <meta name="apple-mobile-web-app-capable" content="yes" /> tag is set in the HTML, and the user adds the page to their home screen, when they then launch the app from the home screen icon, the page is rendered using the second user agent string given in the original ticket message, above.
The second user agent example in this ticket has no Safari version number. There is no regular expression to help us. From what I can deduce this is because the page is rendered not technically by Safari, but by a component of iOS. I cannot find any definitive statement of this, but there's a hint in Safari HTML Reference, Supported Meta Tags where the authors write: "The default behavior is to use Safari to display web content". The implication is that with the meta tag set, Safari is not used for the rendering of content. An additional clue is in an Apple mailing list discussion from 2008 suggesting that the UIWebView component sends a different user agent string.
I suggest that as Apple do not consider this to be Safari, nor should Lift, but that we document the situation on the Wiki.
From my use-case, I wish to treat these two user agents as the same. As such checking for "iPhone.*Mobile" in the UA is enough, for me, and I do not need a version. But we should be aware that other browsers will come and go, and others will have different use-cases, so it may be wise to make isIPhone pluggable with a user supplied function (for example, just checking for /iPhone/ will match both Safari user agents and the Opera iPhone browser user agent).
Additional Background: The user experience is that when the <meta name="apple-mobile-web-app-capable" content="yes" /> tag is set in the HTML, and the user adds the page to their home screen, when they then launch the app from the home screen icon, the page is rendered using the second user agent string given in the original ticket message, above.