Reputation: 151
Is there a way to check (server side) if a request came from a webview or the native browser on iPhone/iPad?
Upvotes: 1
Views: 964
Reputation: 32280
Check if the user agent string contains the word Safari then its from Mobile Safari browser for sure.
FYI:
In UIWebView or WkWebView user agent string can be changed programatically
Upvotes: 0
Reputation: 299355
If you control the application that has the webview, you can install an NSURLProtocol
that will modify the requests before sending them out. This can change the user agent, or add some other custom header that you can interrogate. Of course this is not a security measure; anyone could craft the same header, but it would allow you to customize your response based on whether the client is claiming to be your app.
I keep meaning to blog on NSURLProtocol
because there aren't a lot of examples out there, but for now you can take a look at how PandoraBoy does it in ProxyURLProtocol.
Upvotes: 1
Reputation: 8090
Webviews use Safari framework, so they report Safari for iPhone as user-agent. Requests from Safari or webview won't be any different.
Upvotes: 0