WKWebview 点击电话 href=“tel:xxx”没有效果是为什么?
高洛峰2017-04-17 18:01:54
在點擊打電話這個按鈕的時候需要在這個
-(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationPollowicy)navigationAction decisionHandler:(void (^)(WKNavigationPollowicydler))decisionatdlerydler(FallAction );
然後在代理方法中- (void)webView:(WKWebView )webView didStartProvisionalNavigation:(WKNavigation
)navigation判斷[webView.URL absoluteString])navigation
判斷[webView.URL absoluteString]
貼上代碼:
//如果不實作這個代理方法,預設會屏蔽掉打電話等url
-(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(idity)(WavigationActiongActionHy)navigationAction decisionHandler:(iddation)(Waviid);
decisionHandler(WKNavigationActionPolicyAllow);
}
(void)webView:(WKWebView )webView didStartProvisionalNavigation:(WKNavigation )navigation
{
NSString *path=[YKBDateHelper convertNull:[webView.URL absoluteString]];
NSString * newPath = [path lowercaseString];
if ([newPath hasPrefix:@"sms:"] || [newPath hasPrefix:@"tel:"]) {
UIApplication * app = [UIApplication sharedApplication];
if ([app canOpenURL:[NSURL URLWithString:newPath]]) {
[app openURL:[NSURL URLWithString:newPath]];
}
return;
}
}
PHPz2017-04-17 18:01:54
-(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
sionHandler這個方法中 列印一下navigationAction.navigationType 這個的值 如果是0的話要特殊處理