WKWebview iOS 11点击手势+外部链接

时间:2018-09-27 11:33:49

标签: ios hyperlink wkwebview uitapgesturerecognizer

我已将点击手势添加到WKWebview。添加点击手势后,外部链接点击事件不起作用。不调用DecidePolicyForNavigationAction。但是一切都可以在iOS-12中正常运行。早期版本不起作用。

 - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSString* urlScheme = [[navigationAction.request URL] scheme];
if ([urlScheme isEqualToString:@"http"] || [urlScheme isEqualToString:@"https"]) {
    // FOR HTTP/HTTPS TO OPEN WITHIN THE APP
ExternalWebBrowser* externalWebBrowser = [[ExternalWebBrowser alloc] init];
    externalWebBrowser.externalURL = [navigationAction.request URL];
        [self.navigationController pushViewController:externalWebBrowser animated:YES];
        decisionHandler(WKNavigationActionPolicyCancel);
}
return decisionHandler(WKNavigationActionPolicyAllow);
}


 - (void)userDidTapWebView:(UITapGestureRecognizer *)gesture {
//This method is calling always in iOS 11 and earlier.  Even I tap on WKWebview link. 
 }

0 个答案:

没有答案