美文网首页
APP跳转到手机淘宝

APP跳转到手机淘宝

作者: Fade1992 | 来源:发表于2016-09-14 12:33 被阅读0次

    废话不说上代码

    - (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.同时添加白名单

    LSApplicationQueriesSchemes 照着写好了 白名单

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

    相关文章

      网友评论

          本文标题:APP跳转到手机淘宝

          本文链接:https://www.haomeiwen.com/subject/zxyvettx.html