カメラ権限およびブート設定
2100 ワード
初めてカメラを使用する前に、「カメラの使用を許可するかどうか」というメッセージが表示され、権限要求を拒否すると、カメラを正常に使用できません.以下にカメラ権限状態の判断、および関連するブート設定を示します.
#pragma mark
- (void)cameraPrivilege
{
NSString *mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus ==AVAuthorizationStatusRestricted)
{//
NSLog(@"Restricted");
}
else if(authStatus == AVAuthorizationStatusDenied)
{//
[self goToSettingCameraPrivilege];
return;
}
else if(authStatus == AVAuthorizationStatusAuthorized)
{//
}
else if(authStatus == AVAuthorizationStatusNotDetermined)
{
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
if(granted)
{//
}
else
{//
[self goToSettingCameraPrivilege];
}
}];
}
else
{
//
}
}
#pragma mark
- (void)goToSettingCameraPrivilege
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@" " message:@" , , ?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *confirm = [UIAlertAction actionWithTitle:@" " style:0 handler:^(UIAlertAction * _Nonnull action) {
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:settingsURL])
{
[[UIApplication sharedApplication] openURL:settingsURL];
}
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@" " style:1 handler:^(UIAlertAction * _Nonnull action) {
}];
[alertController addAction:confirm];
[alertController addAction:cancel];
[self presentViewController:alertController animated:YES completion:nil];
}];
}