前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ios app url scheme跳转到淘宝商品详情页 唤醒app

ios app url scheme跳转到淘宝商品详情页 唤醒app

作者头像
用户1219438
发布2018-02-01 15:49:04
5.1K0
发布2018-02-01 15:49:04
举报
文章被收录于专栏:AliceAlice

好的东西就应该大家一块分享。

今天项目中要求,类似于启动页是淘宝的广告,然后点击广告,跳转到淘宝的详情页。

实现这个要求我是各种百度,不过最后发现呢,大部分东西都是千篇一律。

第一种:只是提供了天猫的跳转,并没有提供淘宝的跳转。

第二种:就是使用阿里百川的sdk,这样的话对我我来说是觉得有点大材小用的毕竟只是一个广告页而已。

第三种:就是我通过不懈的努力,终于被我给发现了。

现在我就要记录下来。

- (void)showItemInTmall4iOS:(NSString *)itemId
{
    NSURL *url;
    if([itemId rangeOfString:@"detail.tmall."].location != NSNotFound)   //判断Url是否是天猫商品的链接
    {
        NSRange range = [itemId rangeOfString:@"id="]; //在URL中找到商品的ID
        if(range.location != NSNotFound)
        {
            NSString *productID = [itemId substringWithRange:NSMakeRange(range.location + 3, 11)];
            NSString *appUrl = [NSString stringWithFormat:@"tmall://tmallclient/?{\"action\":\"item:id=%@\"}", productID];
            url = [NSURL URLWithString:[appUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            if ([[UIApplication sharedApplication] canOpenURL:url])
            {
                // 如果已经安装天猫客户端,就使用客户端打开链接
                [[UIApplication sharedApplication] openURL:url];
            }
            else
            {
                //客户手机上没有装天猫客户端,这时启动浏览器以网页的方式浏览该商品。
                url = [NSURL URLWithString:[itemId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
                [[UIApplication sharedApplication] openURL:url];
 
            }
        }
    }
}
 
- (void)showItemInTaobao4iOS:(NSString *)itemId
{
    // 构建淘宝客户端协议的 URL
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"taobao://item.taobao.com/item.htm?id=%@", itemId]];
     
    // 判断当前系统是否有安装淘宝客户端
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        // 如果已经安装淘宝客户端,就使用客户端打开链接
        [[UIApplication sharedApplication] openURL:url];
         
    } else {
        // 否则使用 Mobile Safari 或者内嵌 WebView 来显示
        url = [NSURL URLWithString:[NSString stringWithFormat:@"http://item.taobao.com/item.htm?id=%@", itemId]];
        //        [[UIApplication sharedApplication] openURL:url];
         
        [self tongwanWeb:url];
    }
     
}

 这样就可以了,简单大方。

-------

有同学反映说,为什么按照你的代码写了,但是不好使呢?

eeee,这个问题

要成功的实现跳转,你需要做的工作  还有 就是需要在plist文件里边的url 里边分别添加上 淘宝 跟天猫的url

分别是 CFBundleURLTypes     taobao - taobao   tmall://  - tmall:// 

还有就是需要在下边的

LSApplicationQueriesSchemes

taobao

tmall

果然 用心爱过的人不会忘,用心做过的程序记记也能记起来。

-----------跳转京东客户端

-(void)tojd:(NSString *)itemId{
    
    //这个是京东店铺的链接
//    https://jinjinshang.jd.com
    //这个是京东的商品链接
//    https://item.jd.com/4922289.html
//
//
//    方法1
//     URL详情页
    NSString *qianUrl  = @"openapp.jdmobile://virtual?params=%7B%22sourceValue%22:%220_productDetail_97%22,%22des%22:%22productDetail%22,%22skuId%22:%22";
    NSString *skuid = @"4922289";
    NSString *houUrl  =@"%22,%22category%22:%22jump%22,%22sourceType%22:%22PCUBE_CHANNEL%22%7D";
    NSString *urlString=[NSString stringWithFormat:@"%@%@%@",qianUrl,skuid,houUrl];
    NSURL *url=[NSURL URLWithString:urlString];
    [[UIApplication sharedApplication] openURL:url];
    
    
    

    
    // 判断当前系统是否有安装淘宝客户端
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        // 如果已经安装淘宝客户端,就使用客户端打开链接
        [[UIApplication sharedApplication] openURL:url];
        
    } else {
        // 否则使用 Mobile Safari 或者内嵌 WebView 来显示
        
        NSString *url = [NSString stringWithFormat:@"http://item.taobao.com/item.htm?id=%@",itemId];
        LSH5VC *vc = [[LSH5VC alloc]init];
        vc.webUrl = url;
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-08-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档