温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

html5中怎么指定app页面跳转

发布时间:2022-02-28 17:04:40 来源:亿速云 阅读:297 作者:iii 栏目:开发技术

本文小编为大家详细介绍“html5中怎么指定app页面跳转”,内容详细,步骤清晰,细节处理妥当,希望这篇“html5中怎么指定app页面跳转”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

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和参数。

h6那边只需要执行:

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;
}

读到这里,这篇“html5中怎么指定app页面跳转”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI