美文网首页
UIWebView设置userAgent拦截广告

UIWebView设置userAgent拦截广告

作者: 暖风惜人 | 来源:发表于2019-03-21 09:29 被阅读0次

废话不多说,直接上代码,此方法需要在网页初始化加载链接之前就行调用。

-(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

    }

}

调用如下

 [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"];

相关文章

网友评论

      本文标题:UIWebView设置userAgent拦截广告

      本文链接:https://www.haomeiwen.com/subject/vpvfvqtx.html