wkwebview_tel

wkwebview中屏蔽了tel的url所以我们要用下面这些代码来解决js调用源生iOS系统拨打电话不能的问题;而uiwebview中不会有这样的问题

Swift 4

1
2
3
4
5
6
7
extension ViewController {
//add WKWebView
fileprivate func addWkWebView() {
if #available(iOS 10.0, *) {
configuration.dataDetectorTypes = .phoneNumber
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
extension ViewController: WKNavigationDelegate{
//服务器开始请求的时候调用
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if navigationAction.request.url?.scheme == "tel" {
UIApplication.shared.openURL(navigationAction.request.url!)
decisionHandler(.cancel)
} else {
decisionHandler(.allow)
}
let URL = navigationAction.request.url
print("URL = \(String(describing: URL))");
}
}
坚持原创技术分享,您的支持将鼓励我继续创作!
0%