ionic3 出现莫名广告

应用上线出现 有莫名其妙的广告弹出。javascript

1,DNS被劫持
2,第三方包带广告
3,Http被劫持

wifi和4G网都出现了广告,因此能够直接排除DNS被劫持的问题  java

广告页只会在H5的页面出现,因此基本能够排除第三方包带广告的问题,因此问题基本能够肯定是Http被劫持了。web

网上几乎全部文章的解决方案都是使用Https替换Http。服务器

经过查看Android原生WebView的拦截日志,发现了广告页面的地址是会被拦截到的,而咱们本身的H5页面放在本身的服务器上,IP和端口号是固定的当前使用服务器的ip和端口,广告页的ip和端口确定和咱们是不一致的。拦截了url,将广告url拦截而且不容许它继续执行打开。

webView.setWebViewClient( new WebViewClient() {
// Load opened URL in the application instead of standard browser
// application
public boolean shouldOverrideUrlLoading(WebView view, String url) {
showLogInfo("拦截到的url----"+url);
String advertising="http://"+sharedPreferencesUtil.getData(Constant.IP, RequestConfig.IP) +":"+sharedPreferencesUtil.getData(Constant.PORT,RequestConfig.IPPORT);
if (url.contains(pre)) {
Map<String, String> map = getParamsMap(url, pre);
String code = map.get("code");
String data = map.get("data");
parseCode(code, data); return true;
}
else if(!url.contains(advertising)){
showLogError("拦截到植入广告,广告的url——"+url); return true; }
else{
return false; } }
}
);
相关文章
相关标签/搜索