iOS H5支付WKWebview中无法拉起支付宝/微信客户端支付解决方法

  • Post author:
  • Post category:其他


转自:

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);
    }
}