I have a webview app tool, which essentially consists of the webview and two buttons on a toolbar. One button to view the source of the page, and another button to view/change the current User Agent.
I have both functions working on iOS 5 (view source, and change User Agent), but I cant seem to grab the User Agent in iOS 4.x.
I’m using the following now:
userAgentViewController.UAText = [self.webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
This works in iOS5, but in iOS 4.x, it doesnt return anything. Is there a way to achieve the same functionality in iOS 4.x?
Thank you!
to get the useragent, check the HTTP header in the NSURLRequest of your response.
You can retreive this one in the webViewDidFinishLoad delegate method.
to set it, you have to custom an NSMutableURLRequest and give it to your webView
and that’s it !