iOS获取UserAgent

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

你可能感兴趣的:(iOS获取UserAgent)