配置schame白名单
/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:@""].location != NSNotFound) {NSRange range = [[url absoluteString] rangeOfString:@"/"];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:@""].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:@""].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:@""].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:@""].location != NSNotFound) {NSURL *schemeUrl = [NSURL URLWithString:@"openApp.jdMobile://"];if ([[UIApplication sharedApplication] canOpenURL:schemeUrl]){return YES;}}if([urlStr rangeOfString:@""].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-/view-486463.html