码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 10跳转到其他app

时间:2018-05-24 16:42:45      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:客户   default   pen   nsurl   tun   share   and   efault   cancel   

- (BOOL)jumpsToThirdAPP:(NSString *)urlStr{
    if ([urlStr hasPrefix:@"mqq"] ||
        [urlStr hasPrefix:@"weixin"] ||
        [urlStr hasPrefix:@"alipay"]) {
        if (@available(iOS 10.0, *)) {
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlStr] options:@{} completionHandler:nil];
            return YES;
        } else {
            BOOL success = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlStr]] ;
            if (success) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
            }else{
                NSString *appurl = [urlStr hasPrefix:@"alipay"]?@"https://itunes.apple.com/cn/app/%E6%94%AF%E4%BB%98%E5%AE%9D-%E8%AE%A9%E7%94%9F%E6%B4%BB%E6%9B%B4%E7%AE%80%E5%8D%95/id333206289?mt=8":([urlStr hasPrefix:@"weixin"]?@"https://itunes.apple.com/cn/app/%E5%BE%AE%E4%BF%A1/id414478124?mt=8":@"https://itunes.apple.com/cn/app/qq/id444934666?mt=8");
                NSString *title = [urlStr hasPrefix:@"mqq"]?@"QQ":([urlStr hasPrefix:@"weixin"]?@"微信":@"支付宝");
                NSString *titleString = [NSString stringWithFormat:@"该设备未安装%@客户端",title];
                UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:titleString preferredStyle:UIAlertControllerStyleAlert];
                
                [controller addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                    
                }]];
                
                [controller addAction:[UIAlertAction actionWithTitle:@"立即安装" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    NSURL *url = [NSURL URLWithString:appurl];
                    [[UIApplication sharedApplication] openURL:url];
                }]];
                [self presentViewController:controller animated:YES completion:nil];
            }
            return YES;        }
        
        
    }
    
    return NO;
}

 

或者使用url scheme来进行跳转,相对简单,但是有拒绝风险

iOS 10跳转到其他app

标签:客户   default   pen   nsurl   tun   share   and   efault   cancel   

原文地址:https://www.cnblogs.com/lidarui/p/9083012.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!