让用户设置打开照相机,不打开不让进
- (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){
//跳转目的页面,用户未选择
}
}
网友评论