如何使用Html5跳转到APP指定页面

这篇文章主要介绍如何使用Html5跳转到APP指定页面,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

创新互联公司专注于遵义企业网站建设,成都响应式网站建设,商城开发。遵义网站建设公司,为遵义等地区提供建站服务。全流程按需求定制开发,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

1.设置urlschemes

如何使用Html5跳转到APP指定页面

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

如何使用Html5跳转到APP指定页面

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指定页面”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!

文章题目:如何使用Html5跳转到APP指定页面
文章出自:https://www.cdcxhl.com/article20/gpgojo.html

成都网站建设公司_创新互联,为您提供关键词优化电子商务移动网站建设网站建设搜索引擎优化网站改版

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站制作