iOS获取UserAgent

2018-04-19  本文已影响0人  萌咚咚

UIWebView获取UserAgent

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
NSLog(@"%@",userAgent);

WKWebView获取UserAgent

_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) configuration:configuration];
[_webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(NSString  * _Nullable result, NSError * _Nullable error) {
        
        NSLog(@"============%@",result);
    }];

注意:WKWebView获取UserAgent默认为异步执行的

打印结果:
Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E217

上一篇 下一篇

猜你喜欢

热点阅读