转自:
https://blog.csdn.net/weixin_39726131/article/details/111483766
#import <WebKit/WKNavigationAction.h>
#import <WebKit/WKNavigationDelegate.h>
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
NSURL *URL = navigationAction.request.URL;
NSString * urlStr = [[URL absoluteString] stringByRemovingPercentEncoding];
if ([urlStr containsString:@"weixin://wap/pay"] || [urlStr containsString:@"alipay://alipayclient"])
{
[[UIApplication sharedApplication] openURL:navigationAction.request.URL];
decisionHandler(WKNavigationActionPolicyCancel);
}
else
{
// 在发送请求之前,决定是否跳转
decisionHandler(WKNavigationActionPolicyAllow);
}
}