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


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

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

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

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

    第二种:就是使用阿里百川的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];
            
        }
        
    }
    
    对上述的代码,有任何疑问,可以在下方留言。 也可以给我发邮件咨询:673658917@qq.com 或者是直接加qq:673658917 转载请注明出处,谢谢合作。 睡觉舒服,那是给死人准备的,加油吧,一年后你会感谢现在的自己的。
  • 相关阅读:
    JDBC连接
    Ubuntu 16.04安装MySQL(5.7.18)
    AOP拦截日志报错llegalStateException: It is illegal to call this method if the current request is not in asynchronous mode
    mybatis笔记
    打扮IDEA更换主题
    简单的IDEA破解到2099年
    UML之时序图详解
    UML之类图详解
    UML之用例图详解
    spring和springboot常用注解总结
  • 原文地址:https://www.cnblogs.com/lishanshan/p/7365270.html
Copyright © 2020-2023  润新知