Heim > Fragen und Antworten > Hauptteil
WKWebview 点击电话 href=“tel:xxx”没有效果是为什么?
高洛峰2017-04-17 18:01:54
在点击打电话这个按钮的时候需要在这个
-(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
代理方法中返回decisionHandler(WKNavigationActionPolicyAllow);
然后在代理方法中- (void)webView:(WKWebView )webView didStartProvisionalNavigation:(WKNavigation )navigation
判断[webView.URL absoluteString]
贴上代码:
//如果不实现这个代理方法,默认会屏蔽掉打电话等url
-(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
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
这个方法中 打印一下navigationAction.navigationType 这个的值 如果是0的话要特殊处理