WKWebView 报错unsupported URL
最近在使用wkwebview 使用的时候坑比较多,比如在自定义的 URL Scheme 类型链接 会报错 unsupported URL
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
NSURL *currentURL = navigationAction.request.URL;
NSString *urlString = (currentURL) ? currentURL.absoluteString : @"";
if ([urlString containsString:@"weixin://wap/pay"]) {
[[UIApplication sharedApplication] openURL:self.currentUrl];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
decisionHandler(WKNavigationActionPolicyAllow);
}
WKWebView 点击a 标签中的pdf 不跳转
有一种情况是不允许 跳转
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
NSLog(@"%@",navigationResponse.response.URL.absoluteString);
//允许跳转
decisionHandler(WKNavigationResponsePolicyAllow);
}
还有一种情况 就是 点击 a 标签跳转 blank
-(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
return nil;
}
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
if (navigationAction.targetFrame == nil) {
[webView loadRequest:navigationAction.request];
}
}
希望可以解决你的问题