iOS相机权限设置

iOS相机权限设置,第1张

 摄像头权限未开启时d框跳转到设置页面

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];//读取设备授权状态
if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
    UIAlertController *alertCtrl = [UIAlertController alertControllerWithTitle:@"打开摄像头失败" message:@"请在 设置-隐私-相机 开启权限" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alertCtrl addAction:cancelAction];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }];
    [alertCtrl addAction:okAction];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertCtrl animated:YES completion:nil];
    });
}

AVAuthorizationStatus枚举取值: 

typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
    AVAuthorizationStatusNotDetermined = 0, //用户还没有对应用程序授权进行 *** 作
    AVAuthorizationStatusRestricted,        //还没有授权访问的照片数据
    AVAuthorizationStatusDenied,            //用户拒绝对应用程序授权
    AVAuthorizationStatusAuthorized         //用户对应用程序授权
} NS_AVAILABLE_IOS(7_0);  

判断摄像头是否可用

// 判断设备是否有摄像头  
- (BOOL) isCameraAvailable{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}

// 前面的摄像头是否可用  
- (BOOL) isFrontCameraAvailable{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
}

// 后面的摄像头是否可用  
- (BOOL) isRearCameraAvailable{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/989522.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存