需要注意的是需要获取原来的UIWebView的User-Agent,然后拼接上自己新的User-Agent,貌似直接替换原来的无效,另外,修改User-Agent之后重新创建UIWebView加载网页
?// 修改ua
UIWebView* tempWebView = [[UIWebViewalloc] initWithFrame:CGRectZero];
NSString* userAgent = [tempWebViewstringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
NSString *ua = [NSStringstringWithFormat:@"%@\\%@",
userAgent,
@" / ZhuShou Browser"];
[[NSUserDefaultsstandardUserDefaults] registerDefaults:@{@"UserAgent" : ua,@"User-Agent" : ua}];
NSMutableURLRequest *request =[NSMutableURLRequestrequestWithURL:[NSURLURLWithString:myBxd(self.uid)]];
web = [[UIWebViewalloc] init];
web.frame = CGRectMake(0, navHeight, ApplicationScreenWidth,ApplicationScreenHeight - navHeight);
[web loadRequest:request];
web.delegate = self;
[websizeToFit];
[self.viewaddSubview:web];