arango_86
arango_86

Reputation: 4425

How to get browser UserAgent string from iOS 8 onwards?

Is there any other ways to get iOS browser UserAgent string other than using the following methodology? Please help.

WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
[webView loadHTMLString:@"<html></html>" baseURL:nil];

[webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id __nullable userAgent, NSError * __nullable error) {
        NSLog(@"%@", userAgent);
}];

Upvotes: 2

Views: 2390

Answers (1)

Renandus
Renandus

Reputation: 53

Try this :

UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];

Upvotes: 2

Related Questions