WKWebview 点击电话 href=“tel:xxx”没有效果是为什么?
高洛峰2017-04-17 18:01:54
When you click the call button, you need to return
decisionHandler(WKNavigationActionPolicyAllow) in this
-(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandlerproxy method );
Then in the proxy method - (void)webView:(WKWebView )webView didStartProvisionalNavigation:(WKNavigation )navigation
Judge [webView.URL absoluteString]
Paste the code:
//If you do not implement this proxy method, urls such as phone calls will be blocked by default
-(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;
}
}
ringa_lee2017-04-17 18:01:54
Excuse me, has this problem been solved? I also encountered the same problem
PHPz2017-04-17 18:01:54
Is it because of the Chinese colon used?
Similar to <a href="tel:xxx">xxx</a>
, there will be no problem.
PHPz2017-04-17 18:01:54
-(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
In this method, print the value of navigationAction.navigationType. If it is 0, special treatment is required