//在发送请求之前,决定是否跳转,在这个WKNavigationDelegate方法里
- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void(^)(WKNavigationActionPolicy))decisionHandler{
decisionHandler(WKNavigationActionPolicyAllow);
if ([navigationAction.request.URL.absoluteString hasPrefix:@"weixin://")
{
//decisionHandler(WKNavigationActionPolicyCancel);
if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL])
{
if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)])
{
[[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:^(BOOL success) {
}];
}
else
{
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
}
}
}
}
存在的问题:不能返回APP,而是返回了浏览器,希望解决的大神私聊说下方案,谢谢!
参考链接:https://www.zhihu.com/question/29425158/answer/257209284
已解决参考:https://www.jianshu.com/p/0d8dd04fe94e