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."); }
ios objective-c iphone camera
Ethan Allen Sep 27 '14 at 1:23 2014-09-27 01:23
source share