iOS 跳转淘宝、天猫、京东商品详情页
2017-10-09 14:41
666 查看
配置schame白名单
http://www.jianshu.com/p/40ea9c242ef0代码部分
if([self canGoToTaoBao:url]) { // 如果可以打开淘宝 NSString *urlStr = [url absoluteString]; NSString *agreement = [urlStr substringToIndex:5]; NSString *httpsUrl = [urlStr stringByReplacingOccurrencesOfString:@"https" withString:@"taobao"]; NSString *httpUrl = [urlStr stringByReplacingOccurrencesOfString:@"http" withString:@"taobao"]; NSString *taobaoUrl = [agreement isEqualToString:@"https"]?httpsUrl:httpUrl; NSURL *newUrl = [NSURL URLWithString:taobaoUrl]; [[UIApplication sharedApplication] openURL:newUrl options:@{} completionHandler:nil]; }// 天猫 else if([self canGoToTianMaoDetail:url]) { NSRange range = [[url absoluteString] rangeOfString:@"&id="]; NSString *productID = [[url absoluteString] substringWithRange:NSMakeRange(range.location + 4, 11)]; NSString *urlStr = [NSString stringWithFormat:@"tmall://tmallclient/?{\"action\":\"item:id=%@\"}", productID]; NSURL *newUrl = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication] openURL:newUrl options:@{} completionHandler:nil]; } // 京东 else if([self canGoToJingDongDetail:url]) { if([[url absoluteString] rangeOfString:@"item.jd.com"].location != NSNotFound) { NSRange range = [[url absoluteString] rangeOfString:@"item.jd.com/"]; NSString *productID = [[url absoluteString] substringWithRange:NSMakeRange(range.location + 12, 7)]; NSString *urlStr = [NSString stringWithFormat:@"openApp.jdMobile://virtual?params={\"category\":\"jump\",\"des\":\"productDetail\",\"skuId\":\"%@\",\"sourceType\":\"homefloor\",\"sourceValue\":\"4384\",\"landPageId\":\"jshop.cx.mobile\"}", productID]; NSURL *newUrl = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication] openURL:newUrl options:@{} completionHandler:nil]; } if([[url absoluteString] rangeOfString:@"jd.com"].location != NSNotFound && [[url absoluteString] rangeOfString:@"/item/"].location != NSNotFound) { NSRange range = [[url absoluteString] rangeOfString:@"/item/"]; NSString *productID = [[url absoluteString] substringWithRange:NSMakeRange(range.location + 6, 7)]; NSString *urlStr = [NSString stringWithFormat:@"openApp.jdMobile://virtual?params={\"category\":\"jump\",\"des\":\"productDetail\",\"skuId\":\"%@\",\"sourceType\":\"homefloor\",\"sourceValue\":\"4384\",\"landPageId\":\"jshop.cx.mobile\"}", productID]; NSURL *newUrl = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication] openURL:newUrl options:@{} completionHandler:nil]; } } else { // 跳转至 webView }
- (BOOL) canGoToTaoBao:(NSURL *)url { NSString *urlStr = [url absoluteString]; if([urlStr rangeOfString:@"taobao.com"].location != NSNotFound) { NSURL *schemeUrl = [NSURL URLWithString:@"taobao://"]; if ([[UIApplication sharedApplication] canOpenURL:schemeUrl]){ return YES; } } return NO; } - (BOOL) canGoToTianMaoDetail:(NSURL *)url { NSString *urlStr = [url absoluteString]; if([urlStr rangeOfString:@"tmall.com"].location != NSNotFound && [urlStr rangeOfString:@"&id="].location != NSNotFound) { NSURL *schemeUrl = [NSURL URLWithString:@"tmall://"]; if ([[UIApplication sharedApplication] canOpenURL:schemeUrl]){ return YES; } } return NO; } - (BOOL) canGoToJingDongDetail:(NSURL *)url { NSString *urlStr = [url absoluteString]; if([urlStr rangeOfString:@"item.jd.com"].location != NSNotFound) { NSURL *schemeUrl = [NSURL URLWithString:@"openApp.jdMobile://"]; if ([[UIApplication sharedApplication] canOpenURL:schemeUrl]){ return YES; } } if([urlStr rangeOfString:@"jd.com"].location != NSNotFound && [urlStr rangeOfString:@"/item/"].location != NSNotFound) { NSURL *schemeUrl = [NSURL URLWithString:@"openApp.jdMobile://"]; if ([[UIApplication sharedApplication] canOpenURL:schemeUrl]){ return YES; } } return NO; }
附:
京东相关跳转协议:https://www.china-7.net/view-486463.html
相关文章推荐
- 在iOS应用中跳转到淘宝或天猫客户端商品详情页
- iOS开发 仿淘宝,京东商品详情3D动画
- Android自定义控件-仿淘宝ios客户端天猫商品详情界面动效
- 天猫、淘宝、京东商品详情的图片手动滑动ViewPager
- Android自定义控件-仿淘宝ios客户端天猫商品详情界面动效
- Android自定义控件-仿淘宝ios客户端天猫商品详情界面
- 安卓 跳转淘宝、京东app,并打开商品详情页
- Android跳转淘宝、京东APP商品详情页
- Android仿京东、天猫app的商品详情页的布局架构, 以及功能实现
- Android高阶UI之仿京东、天猫app的商品详情页
- iOS 类似淘宝商品详情查看翻页效果的实现
- 实现淘宝商品详情页面的viewPager滑动到最后一张图片跳转的功能
- 仿京东、淘宝、一号店商品详情上拉显示图文详情
- Android仿京东、天猫商品详情页
- 仿淘宝、京东拖拽商品详情(可嵌套ViewPager、ListView、WebView、FragmentTabhost)
- 仿京东、淘宝商品详情页上拉显示详情的嵌套ScrollView
- Android仿京东、天猫app的商品详情页的布局架构, 以及功能实现
- android 仿淘宝、京东商品详情页 向上拖动查看图文详情控件
- 方维,将采集到的淘宝天猫商品详情里面的链接转换成淘宝客链接
- ios 仿京东商品详情(背景缩小,下部弹出功能)