跳转到天猫客户端

NSString *urlString = @"http://detail.tmall.com/item.htm?spm=a215v.7217581.610138.10.sO6nZp&id=36615660686&areaId=410100&cat_id=2&rn=ebe1860b08257aacbac424ed12d5208c&user_id=1098342976&is_b=1";
            NSURL *url;
            if([urlString rangeOfString:@"detail.tmall."].location != NSNotFound)   //判断Url是否是天猫商品的链接
            {
                NSRange range = [urlString rangeOfString:@"id="]; //在URL中找到商品的ID
                if(range.location != NSNotFound)
                {
                    NSString *productID = [urlString 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:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
                        [[UIApplication sharedApplication] openURL:url];
                    }
                }
            }

转载于:https://www.cnblogs.com/tian-sun/p/5019935.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值