H5跳转到APP指定页面
2017-12-22 11:51
841 查看
1.设置urlschemes
urlschemes尽量设一个唯一的字符串,例如可以设为:iOS+公司英文名+ 项目工程名
比如我的设为iOSTencentTest,在浏览器中输入地址iOSTencentTest://即可跳转到我的app
2.跳转到指定页面
在使用iOSTencentTest://打开app会调用AppDelegate的代理方法-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
跳转指定页面在该方法中操作
iOSTencentTest://后面是可以添加参数的,例如iOSTencentTest://goodsDetails?id=xxxxx
goodsDetails可直接通过url.host获取
id=xxxxx 参数可直接通过url.query获取
可以根据自身需求去设置不同的host和参数。
h5那边只需要执行:
window.location.href = 'iOSTencentTest://goodsDetails?id=xxxxx'
附:
//获取Window当前显示的ViewController - (UIViewController*)currentViewController{ //获得当前活动窗口的根视图 UIViewController* vc = [UIApplication sharedApplication].keyWindow.rootViewController; while (1) { //根据不同的页面切换方式,逐步取得最上层的viewController if ([vc isKindOfClass:[UITabBarController class]]) { vc = ((UITabBarController*)vc).selectedViewController; } if ([vc isKindOfClass:[UINavigationController class]]) { vc = ((UINavigationController*)vc).visibleViewController; } if (vc.presentedViewController) { vc = vc.presentedViewController; }else{ break; } } return vc; } //NSString类别方法 //通过url.query获取参数字符 再分成字典 -(NSMutableDictionary *)getURLParameters { if (!self.length) { return nil; } NSMutableDictionary *params = [NSMutableDictionary dictionary]; if ([self containsString:@"&"]) { NSArray *urlComponents = [self componentsSeparatedByString:@"&"]; for(NSString *keyValuePair in urlComponents) { //生成key/value NSArray *pairComponents = [keyValuePair componentsSeparatedByString:@"="]; NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding]; NSString*value = [pairComponents.lastObject stringByRemovingPercentEncoding]; //key不能为nil if(key==nil|| value ==nil) continue; id existValue = [params valueForKey:key]; if(existValue !=nil) { //已存在的值,生成数组。 if([existValue isKindOfClass:[NSArray class]]) { //已存在的值生成数组 NSMutableArray*items = [NSMutableArray arrayWithArray:existValue]; [items addObject:value]; [params setValue:items forKey:key]; }else{ //非数组 [params setValue:@[existValue,value]forKey:key]; } }else{ //设置值 [params setValue:value forKey:key]; } } }else { //单个参数生成key/value NSArray *pairComponents = [self componentsSeparatedByString:@"="]; if(pairComponents.count==1) { return nil; } //分隔值 NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding]; NSString *value = [pairComponents.lastObject stringByRemovingPercentEncoding]; //key不能为nil if(key ==nil|| value ==nil)return nil; //设置值 [params setValue:value forKey:key]; } return params; }
相关文章推荐
- h5页面唤醒app并跳转到指定页面
- H5唤醒app并跳转到指定页面
- Android实现深度链接(APP外带动态参数唤醒APP,并跳转指定页面,APP不论在不在运行都可以)
- iOS 一个app跳转另一个app并实现通信(如A跳到B并打开B中指定页面)
- iOS实现在webview页面内点击链接,跳转指定App
- iOS 从AppDelegate中跳转指定页面
- h5页面唤醒APP指定页面并传参
- JS和安卓互相调用以及Scheme协议完成外部链接跳转app指定页面
- 点击外部链接跳转App指定页面SingleTask模式
- ios 应用中直接跳转到指定app页面 或者 app 评价页面 的方法
- iOS 从一个APP跳转到另一个APP,并带参数跳到指定页面
- 微信6.66版本浏览器网页唤起微信app跳转到指定任意页面二维码识别方法ticket生成
- 基于应用宝实现微信h5页面中打开本地app,如果没有跳转下载页面的解决方案
- ios 应用中直接跳转到指定app页面 或者 app 评价页面 的方法
- JS和安卓互相调用以及Scheme协议完成外部链接跳转app指定页面
- Android之项目开发中在app内Intent意图跳转自己指定的Html5页面
- h5页面唤起app(iOS和Android),没有安装则跳转下载页面
- ios 应用中直接跳转到指定app页面 或者 app 评价页面 的方法
- 详解Android App卸载后跳转到指定的反馈页面的方法