Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know that application have camera access or not programmatically in iOS8

My application uses the camera. In iOS8 they include a new privacy setting, Camera, where the user can manage use of camera rights for each application.

Problem:
If the user didn't allow my application to use camera then how can i know that My application have no access for camera.
like i can use ALAssetsLibrary authorizationStatus to discover the status of the photolibrary or ABAddressBookGetAuthorizationStatus to know status of phonebook access.

Question:
How i can know whether my application has camera access or not in iOS8, so that I may prompt the user to allow camera access for my application?


I have below print screen of Photo booth which having same problem as my application have.

enter image description here

enter image description here

enter image description here


When there is no camera access it will only show black screen no message nothing.
like image 630
Jageen Avatar asked Jul 09 '14 10:07

Jageen


1 Answers

Check AVAuthorizationStatus for camera availability and then handle cases accordingly

AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(status == AVAuthorizationStatusAuthorized) {
  // authorized
} else if(status == AVAuthorizationStatusDenied){
  // denied
} else if(status == AVAuthorizationStatusRestricted){
  // restricted
} else if(status == AVAuthorizationStatusNotDetermined){
  // not determined
  [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
    if(granted){
  NSLog(@"Granted access");
} else {
  NSLog(@"Not granted access");
}
  }];
}
like image 134
Animesh Porwal Avatar answered Sep 28 '22 15:09

Animesh Porwal