WKWebView *_wkWebView; //定义一个全局的变量来保存 不然写在花括号里面被释放掉了
- (void)setUserAgent{
// UIWebView *web = [[UIWebView alloc] init];
// NSString* userAgent = [web stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
// DLog(@"userAgent = %@",userAgent);
// NSString *ua = [NSString stringWithFormat:@"%@\\%@",
// userAgent,
// @"FuKaBrowser"];
// DLog(@"ua = %@",ua);
// [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent" : ua, @"User-Agent" : ua}];
_wkWebView = [[WKWebView alloc] init];//这里不能用UIWebview的创建办法 ,不然获取为空
[_wkWebView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(NSString * _Nullable title, NSError * _Nullable error) {
NSString *ua = [NSString stringWithFormat:@"%@\\%@",
title,
@"FuKaBrowser"];
DLog(@"ua = %@",ua);
[[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent" : ua, @"User-Agent" : ua}];
}];
}