使用URL SCHEME启动天猫客户端并跳转到某个商品页面的方法
2015-12-03 16:50
477 查看
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]; } } }
相关文章推荐
- Android开发笔记(九)特别的.9图片
- PHP_OS常量使用方法
- Face detection in color images, 彩色图像中的人脸检测
- C++实现离散余弦变换(参数为Eigen矩阵)
- 还原data block dumps实际值
- 关于JNI
- 使用kettle向HBase导入数据
- 中国剩余定理POJ1006Biorhythms
- iOS——RSA加密方法
- maven依赖关系中Scope的作用
- iOS 开发过程中----清理缓存的实现
- JSTL之<c:forEach>
- 分享个方便的轮播图,用起来比较方便吧
- C# Enum,Int,String的互相转换
- 关于LabVIEW软件的快捷键
- java时间验证工具
- Unity3D UGUI中Rect Transform的特性
- Service与Android系统实现-- 应用程序里的Service
- (五十一)结构
- 打包工具之命令篇