美文网首页iOS
iOS 用户打开相机拒绝

iOS 用户打开相机拒绝

作者: 若风_412d | 来源:发表于2019-06-10 10:45 被阅读0次

    让用户设置打开照相机,不打开不让进

    - (void)checkOpenAuthorityOfTheCamera{
        
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if(authStatus == AVAuthorizationStatusAuthorized){
    //跳转目的页面,允许打开相机
        }
        else if (authStatus == AVAuthorizationStatusDenied){//跳到应用设置相机的地方
      UIAlertController * alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"xxxxx需要访问你的照相机,请打开照相机权限" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            if ([[UIApplication sharedApplication]canOpenURL:url]) {
                [[UIApplication sharedApplication]openURL:url];
            }
        }];
        [alertVC addAction:cancelAction];
        [alertVC addAction:okAction];
        [self presentViewController:alertVC animated:YES completion:nil];
        
        }
        else if (authStatus == AVAuthorizationStatusNotDetermined){
    //跳转目的页面,用户未选择
        }
        
    }
    

    相关文章

      网友评论

        本文标题:iOS 用户打开相机拒绝

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