UIWebView获取方法:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
//获取UA
NSString *oldAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
//修改拼接UA
NSString *newAgent = [oldAgent stringByAppendingString:[NSString stringWithFormat:@" XXX/%@",AppVersion]];
//保存到本地
NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:newAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];
WKWebView获取方法:
@property (nonatomic, strong) WKWebView *webView;
WKWebView *webView = [[WKWebView alloc]initWithFrame:CGRectZero];
//WKWebView需要先请求一个链接
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com"]]];
__weak typeof(sel