现有一个需求,打开一个app 的网页,浏览方式要像在电脑上的浏览器打开是一样的。查了一下资料,说是设置UserAgent就可以改变。代码如下 :
[_myWebView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
NSString *oldAgent = result;
// // 给User-Agent添加额外的信息
NSString *newAgent = [NSString stringWithFormat:@"%@;%@", oldAgent, @"extra_user_agent"];
// 设置global User-Agent
[[NSUserDefaults standardUserDefaults] synchronize];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
[_myWebView setCustomUserAgent:newAgent]; //iOS9出来的方法
}];
然而并没有什么卵用,查找了一上午的资料都没找到合适的解决方法,最后加了一句代码解决的,特