WKWebView 调用支付宝,微信H5支付调用失败解决

如果你这么写


- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{

    if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {

        [[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{} completionHandler:^(BOOL success) {

        }];

        decisionHandler(WKNavigationActionPolicyAllow);

    }
    else {
        
        decisionHandler(WKNavigationActionPolicyAllow);
        
    }


}

这么写可以调用支付宝,但是微信就会出现参数错误的网页提示。
解决如下,换种写法。如果帮到你,记得回来点赞哦!

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{

    if ([navigationAction.request.URL.absoluteString hasPrefix:@"weixin://"] || [navigationAction.request.URL.absoluteString hasPrefix:@"alipay://"]) {
        
        [[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{} completionHandler:^(BOOL success) {
            
        }];
        
    }
        decisionHandler(WKNavigationActionPolicyAllow);

}

done!

如果这个文章帮到了你,一定给我Star、点击关注哦!

你可能感兴趣的:(WKWebView 调用支付宝,微信H5支付调用失败解决)