标签:absolute ali 技术 last java 外部链接 点击 跳转 click
1、在项目info.plist中添加URL Types以供html调用
2.html代码
<html> <head lang="en"> <meta charset="UTF-8"> <title>支付页面</title> </head> <script type="text/javascript"> var url = location.search; //获取url中"?"符后的字串 var typestr=""; //截取参数 url=xxxx?type=1 if (url.indexOf("?") != -1) { typestr = url.split("type=")[1]; } //支付宝 if(typestr==1){ //支付宝调起应用 window.load=AliPay(); } else if(typestr==2){ //微信调起应用 window.load=Weixin(); } //支付宝调起应用,向应用传参数,0表示不做任何操作,1表示为支付宝调起的app,2表示为微信调起的app function AliPay(){ if(confirm("是否打开支付宝?")){//点击了确定 document.location = "XXXXFromHtml://type:1"; } else{//点击了取消后返回应用 document.location = "XXXXFromHtml://type:0"; } } //微信调起应用 function Weixinclick(){ if(confirm("是否打开微信?")){//点击了确定 document.location = "XXXXFromHtml://type:2"; } else{//点击了取消 document.location = "XXXXFromHtml://type:0"; } } </script> <body> </body> </html>
3.客户端代码
- (BOOL)application:(UIApplication )application openURL:(NSURL )url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{}
//打开外部链接回调 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { //网页调起app外面链接url type NSString *string =url.absoluteString; if ([string hasPrefix:@"xxxxfromhtml://"]) { //截取html传递的参数类型 NSString *type=[[string pathComponents] lastObject]; NSString *typeStr = [[type componentsSeparatedByString:@":"]lastObject]; NSInteger apptype = [typeStr integerValue]; // DebugLog(@"%@",array); BaseNavigationController *nav=(BaseNavigationController*)self.window.rootViewController; //当前离开应用的控制器 if ([[nav.childViewControllers lastObject] isKindOfClass:[XXXXPayViewController class]]) { //从网页调起app,不会调用充值界面方法,需手动调用 XXXXPayViewController *scoreVC=[nav.childViewControllers lastObject]; //在内部调用支付的应用跳转 [scoreVC fromWebHtmlWithType:apptype]; } return YES; } }
标签:absolute ali 技术 last java 外部链接 点击 跳转 click
原文地址:https://www.cnblogs.com/weiboyuan/p/9186910.html