Is there any way to ask the user about access to the Camera after they have already refused iOS 8?

I use this code, but unfortunately it does not work.

After the user has denied access to the camera, I want to ask them for permission to reuse the camera the next time they try to download it (in this case, this is a barcode scanner using the camera view). I always get AVAuthorizationStatusDenied , and then granted always returns NO automatically, although I ask it again in the code.

Many of my users send me an email saying "my screen is black when I try to scan a barcode", and this is because for some reason they refused to access the camera. I want to be able to request them again, because most likely the failure was a mistake.

Is there any way to do this?

  AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if(authStatus == AVAuthorizationStatusAuthorized) { NSLog(@"%@", @"You have camera access"); } else if(authStatus == AVAuthorizationStatusDenied) { NSLog(@"%@", @"Denied camera access"); [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { if(granted){ NSLog(@"Granted access to %@", AVMediaTypeVideo); } else { NSLog(@"Not granted access to %@", AVMediaTypeVideo); } }]; } else if(authStatus == AVAuthorizationStatusRestricted) { NSLog(@"%@", @"Restricted, normally won't happen"); } else if(authStatus == AVAuthorizationStatusNotDetermined) { NSLog(@"%@", @"Camera access not determined. Ask for permission."); [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { if(granted){ NSLog(@"Granted access to %@", AVMediaTypeVideo); } else { NSLog(@"Not granted access to %@", AVMediaTypeVideo); } }]; } else { NSLog(@"%@", @"Camera access unknown error."); } 
+48
ios objective-c iphone camera
Sep 27 '14 at 1:23
source share
3 answers

After some research, it looks like you cannot do what I would like. Here is an alternative that I encoded to open a dialog and open the Settings app automatically if on iOS 8+.

 - (IBAction)goToCamera { AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if(authStatus == AVAuthorizationStatusAuthorized) { [self popCamera]; } else if(authStatus == AVAuthorizationStatusNotDetermined) { NSLog(@"%@", @"Camera access not determined. Ask for permission."); [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { if(granted) { NSLog(@"Granted access to %@", AVMediaTypeVideo); [self popCamera]; } else { NSLog(@"Not granted access to %@", AVMediaTypeVideo); [self camDenied]; } }]; } else if (authStatus == AVAuthorizationStatusRestricted) { // My own Helper class is used here to pop a dialog in one simple line. [Helper popAlertMessageWithTitle:@"Error" alertText:@"You've been restricted from using the camera on this device. Without camera access this feature won't work. Please contact the device owner so they can give you access."]; } else { [self camDenied]; } } 

Failure Warning:

 - (void)camDenied { NSLog(@"%@", @"Denied camera access"); NSString *alertText; NSString *alertButton; BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL); if (canOpenSettings) { alertText = @"It looks like your privacy settings are preventing us from accessing your camera to do barcode scanning. You can fix this by doing the following:\n\n1. Touch the Go button below to open the Settings app.\n\n2. Touch Privacy.\n\n3. Turn the Camera on.\n\n4. Open this app and try again."; alertButton = @"Go"; } else { alertText = @"It looks like your privacy settings are preventing us from accessing your camera to do barcode scanning. You can fix this by doing the following:\n\n1. Close this app.\n\n2. Open the Settings app.\n\n3. Scroll to the bottom and select this app in the list.\n\n4. Touch Privacy.\n\n5. Turn the Camera on.\n\n6. Open this app and try again."; alertButton = @"OK"; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:alertText delegate:self cancelButtonTitle:alertButton otherButtonTitles:nil]; alert.tag = 3491832; [alert show]; } 

Delegate a call to UIAlertView:

 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if (alertView.tag == 3491832) { BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL); if (canOpenSettings) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; } } 
+74
Sep 27 '14 at 2:07
source share

As soon as they refuse access to the camera, the user can allow the use of the camera for your application in the settings. By design, you cannot override this in your own code.

You can discover this case with the following code example, and then explain to the user how to fix it: iOS 7 UIImagePickerController Camera No Image

 NSString *mediaType = AVMediaTypeVideo; // Or AVMediaTypeAudio AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; // The user has explicitly denied permission for media capture. else if(authStatus == AVAuthorizationStatusDenied){ NSLog(@"Denied"); } 
+9
Sep 27 '14 at 1:26
source share

For Swift 3.0

This will bring the user to the settings for changing the resolution.

 func checkCameraAuthorise() -> Bool { let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) if status == .restricted || status == .denied { let dialog = ZAlertView(title: "", message: "Please allow access to the camera in the device Settings -> Privacy -> Camera", isOkButtonLeft: false, okButtonText: "OK", cancelButtonText: "Cancel", okButtonHandler: { _ -> Void in UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!)}, cancelButtonHandler: { alertView in alertView.dismissAlertView() }) dialog.show() return false } return true } 
+1
May 4 '17 at 2:12 pm
source share



All Articles