func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
print("scheme -------------- :\(navigationAction.request.url?.scheme)")
print("schemeurl -------------- :\(navigationAction.request.url)")
//获取当前的url
let curUrl = navigationAction.request.url
let newcUrUrl = curUrl?.absoluteString ?? ""
// 去除原有的URL回调地址,换成自己的配置
if (newcUrUrl.hasPrefix("https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb")) {
let dic = navigationAction.request.allHTTPHeaderFields
let refer = dic?["Referer"] ?? ""
if refer != "dev.maas.chelaile.net.cn://"{
decisionHandler(WKNavigationActionPolicy.cancel)
//对微信的url 进行处理 拼接 App 的标识
var lastURL = curUrl?.absoluteString ?? ""
let req = NSMutableURLRequest(url: URL(string: lastURL)!)
req.httpMethod = "GET"
req.setValue("dev.maas.chelaile.net.cn://", forHTTPHeaderField: "Referer")
self._webView?.load(req as URLRequest)
return;
}
decisionHandler(WKNavigationActionPolicy.allow)
}else{
decisionHandler(WKNavigationActionPolicy.allow)
}
if navigationAction.request.url?.scheme == "tel" {
//吊起拨打电话
UIApplication.shared.openURL(navigationAction.request.url!);
decisionHandler(WKNavigationActionPolicy.cancel)
}
let scheme = navigationAction.request.url?.scheme ?? ""
if (scheme != "https" && scheme != "http") {
if scheme == "weixin" {
//调用微信
UIApplication.shared.open(navigationAction.request.url!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly:false]) { flag in }
return
}
return
}
}
网友评论