美文网首页
获取相机权限 和 打开相机权限

获取相机权限 和 打开相机权限

作者: 林希品 | 来源:发表于2022-04-28 13:45 被阅读0次
    -(void)openCamera {
        AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        NSLog(@"openCamera_status == %ld",(long)status);
        if (status == AVAuthorizationStatusAuthorized){
            //已经授权了
            
        } else if (status == AVAuthorizationStatusNotDetermined){
            //获取权限
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
    
                dispatch_async(dispatch_get_main_queue(), ^{
    
                    if (granted) {
                        //允许访问
                    }else{
                        //不允许访问
                    }
    
                });
            }];
        }else if (status == AVAuthorizationStatusDenied || status == AVAuthorizationStatusRestricted){ //否认
            //提示打开
            NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            if ([[UIApplication sharedApplication]canOpenURL:url]) {
                  [[UIApplication sharedApplication] openURL:url];
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:获取相机权限 和 打开相机权限

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