在iOS应用中跳转到淘宝或天猫客户端商品详情页

最近做iOS项目的时候遇到一个需求,启动图片后是广告页,点击广告页,跳转到淘宝或天猫的商品详情页。 具体需要是这样:

1)安装了淘宝:跳转到淘宝详情页。

2)没装淘宝,装了天猫:跳转到天猫详情页

3)淘宝、天猫都没装:跳转到应用自己的页面,加载网页。

解决方案:

1)可以使用阿里百川的SDK完成。 文档地址:http://baichuan.taobao.com/doc2/detail.htm?spm=a3c0d.7629140.0.0.fXnfzs&treeId=51&articleId=102860&docType=1

2)拿到淘宝、天猫url scheme及相应的链接,自己完成跳转。代码如下:

 NSURLtaobaoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"taobao://item.taobao.com/item.htm?id=%@", book_id]];

NSURLtmallUrl = [NSURL URLWithString:[[NSString stringWithFormat:@"tmall://tmallclient/?{\"action\":\"item:id=%@\"}", book_id] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

if([[UIApplicationsharedApplication] canOpenURL:taobaoUrl]) {//能打开淘宝就打开淘宝[[UIApplicationsharedApplication] openURL:taobaoUrl];}elseif([[UIApplicationsharedApplication] canOpenURL:tmallUrl]) {//能打开天猫就打开天猫[[UIApplicationsharedApplication] openURL:tmallUrl];}else{//都打不开就自己加载网页KGAdWebVC *adWebVC = [[KGAdWebVC alloc] init];   adWebVC.url= splash_url;    [self.navigationControllerpushViewController:adWebVC animated:YES];}

你可能感兴趣的:(在iOS应用中跳转到淘宝或天猫客户端商品详情页)