I have a webpage that uses custom protocol handlers to open apps. One links to the iTunes store app for people to download Picup app, and another links to fileupload:// to open the Picup app.
When the page is loaded into Safari embedded inside another app (e.g. 1Step Scanner barcode scanner), when navigating to those custom protocols, I get an error message – Error, Failed to Load Webpage! Please Try Again.
I intend to use JavaScript to detect whether the webpage is loaded inside an embedded browser and show a message to ask the user to use Safari.
One way is to detect the user agent string
Embedded
Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A405
Safari
Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3
However, is detecting the presence/absence of the word Safari in the user agent string applicable for all versions of iPhone? Is there a more foolproof method?
Apparently yes, that’s the best way.
Even Chrome for iOs includes the word Safari on requests, so you should be fine with assuming that requests from iOs without the word “Safari” are from an embedded UiWebKit control.