npattan
npattan

Reputation: 151

Check if request came from a webview or browser on iOS?

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

Answers (3)

Durai Amuthan.H
Durai Amuthan.H

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

Rob Napier
Rob Napier

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

Kyr Dunenkoff
Kyr Dunenkoff

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

Related Questions