获取相机权限 和 打开相机权限
2022-04-28 本文已影响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];
}
}
}