在app 内部,使用wkwebview 加载URL,如果h5 需要吊起支付宝微信客户端支付,但是却不能吊起,解决方案如下:
在这个方法里实现如下判断:但微信一般不会走这里,会走失败的unsupport Url
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSString *urlStr = [navigationAction.request.URL.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if ([urlStr containsString:@"alipay://"] || [urlStr containsString:@"weixin://"]) {
[[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{} completionHandler:^(BOOL success) {
}];
}
decisionHandler(WKNavigationActionPolicyAllow);
}
这两个方法内部实现微信吊起的问题
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error{
[self handleError:error];
}
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error{
[self handleError:error];
}
- (void)handleError:(NSError *) error{
NSString *url= error.userInfo[@"NSErrorFailingURLStringKey"];
if ([NSObject nulldata:url]) {
if ([url containsString:@"weixin://"] ||[url containsString:@"alipay://"] ) {
NSURL *alipayURL = [NSURL URLWithString:url];
[[UIApplication sharedApplication] openURL:alipayURL options:@{} completionHandler:^(BOOL success) {
}];
}
}
}