APP跳转到手机淘宝

废话不说上代码

- (void)viewDidLoad {

[super viewDidLoad];

UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];

clickBtn.frame = CGRectMake(100, 100, 50, 50);

[clickBtn setTitle:@"跳转按钮" forState:UIControlStateNormal];[clickBtn sizeToFit];

//    clickBtn setImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>

[clickBtn setBackgroundColor:[UIColor yellowColor]];

[clickBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

[clickBtn addTarget:self action:@selector(clickAction) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:clickBtn];

}

- (void)clickAction{

NSLog(@"跳转到淘宝");

NSURL *appUrl = [NSURL URLWithString:@"taobao://"];;

NSURL *httpUrl = [NSURL URLWithString:@"http://www.taobao.com"];

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

[[UIApplication sharedApplication] openURL:appUrl];

} else {

//打开网页淘宝

[[UIApplication sharedApplication] openURL:httpUrl];

}

}

2.同时添加白名单

APP跳转到手机淘宝_第1张图片

LSApplicationQueriesSchemes 照着写好了 白名单

下面的App Transport Security Settings 是 HTTPS 的白名单

你可能感兴趣的:(APP跳转到手机淘宝)