在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及相应的链接,自己完成跳转。代码如下:

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

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

if ([[UIApplication sharedApplication] canOpenURL:taobaoUrl]) {

//能打开淘宝就打开淘宝

[[UIApplication sharedApplication] openURL:taobaoUrl];

} else if ([[UIApplication sharedApplication] canOpenURL:tmallUrl]) {

//能打开天猫就打开天猫

[[UIApplication sharedApplication] openURL:tmallUrl];

} else {

//都打不开就自己加载网页

KGAdWebVC *adWebVC = [[KGAdWebVC alloc] init];

adWebVC.url = splash_url;

[self.navigationController pushViewController:adWebVC animated:YES];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容