实现原理,判断是否是有alipays://
或者alipay://
,如果有,就直接调用
[[UIApplication sharedApplication]openURL:request.URL];
OC代码
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSString* reqUrl = request.URL.absoluteString;
if ([reqUrl hasPrefix:@"alipays://"] || [reqUrl hasPrefix:@"alipay://"]) {
BOOL bSucc = [[UIApplication sharedApplication]openURL:request.URL];
//bSucc是否成功调起支付宝
if (!bSucc) {
NSLog(@"调用失败");
return NO;
}
}
return YES;
}
Swift代码
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let reqUrl = request.url?.absoluteString
if ((reqUrl?.hasPrefix("alipays://"))! || (reqUrl?.hasPrefix("alipay://"))!)
{
let bSucc:Bool = UIApplication.shared.openURL(request.url!)
if !bSucc {
print("调用失败")
return false
}
}
return true
}