Reputation: 375
I am using camera in my application, and i want to ask for that trendy permission which every other app prompts. How can i get that ?
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized) {
// do your logic
authorized = YES;
[self actionLaunchAppCamera];
} else if(authStatus == AVAuthorizationStatusDenied){
// denied
authorized = NO;
} else if(authStatus == AVAuthorizationStatusRestricted){
// restricted, normally won't happen
} else if(authStatus == AVAuthorizationStatusNotDetermined){
// not determined?!
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
NSLog(@"Granted access to %@", AVMediaTypeVideo);
} else {
NSLog(@"Not granted access to %@", AVMediaTypeVideo);
}
}];
} else {
// impossible, unknown authorization status
}
I am using the above code for checking authorization but it always go inside authorizedstatus condition as it has the permission already. I have checked from privacy settings the permission is already on. But i have never ask for the permission from user.
Thanks everyone.
Upvotes: 1
Views: 1256
Reputation: 91
Edit: Oh, I see what you mean. Then you need to create AVCaptureDeviceInput to see whether permission has been asked before. If not, this prompts the user for permission.
NSError outError = NULL;
AVCaptureDevice captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
If (captureDevice != NULL) {
AVCaptureDeviceInput captureInput = [AVCaptureDeviceInput deviceInputfromDevice:captureDevice error:outError];
If (captureInput != NULL && outError == NULL) {
// we have permission to use the camera
}
}
You don't have to uninstall the app to reset the access permission. Assuming your device is running iOS 8, simply go to the camera settings screen and disable the access:
Upvotes: 1