廢話不多說疼约,直接上代碼卤档,此方法需要在網(wǎng)頁初始化加載鏈接之前就行調(diào)用。
-(void)setChangUserAgent:(NSString*)userAgent{
? ? NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:userAgent, @"UserAgent", nil];
? ? [[NSUserDefaults standardUserDefaults]
?? ? registerDefaults:dictionary];
? ? [[NSUserDefaults standardUserDefaults] synchronize];
? ? [self.view insertSubview:self.webView atIndex:0];
? ? if(@available(iOS11.0, *)) {
? ? ? ? self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
? ? }else{
? ? ? ? self.automaticallyAdjustsScrollViewInsets=NO;
? ? ? ? // Fallback on earlier version
? ? }
}
調(diào)用如下
?[self setChangUserAgent:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36 iphoneapp"];