iOS 添加 UA

获取 UIWebview 的useragent

关于获取 UIWebview 的useragent。我对网上的一种做法实在画面太美不忍看。他们使用UIWebview 去加载一个请求,通过返回来数据(附有 UserAgent 的参数)来获取Useragent,这种做法需要设置webview 代理、发请求、要解析数据、要处理用完的对象。

实际上只需要两行代码就能搞定

[objc]  view plain  copy
 print ?
  1. UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectZero];  
  2. NSString* secretAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];  

猜你喜欢

转载自blog.csdn.net/yxl123546/article/details/71641353