Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect if camera is restricted by user

I'm doing an ios app with a button that launch the camera.

I want to enable/disable the button if the device has a camera available or not.

I want to detect if the device has a camera and also when the device has camera but it's restricted (with this) so you can't use it.

How can I detect these two options?

Thanks

like image 647
A.Vila Avatar asked May 31 '13 11:05

A.Vila


1 Answers

To check camera permission status in app use following snippet.

@import AVFoundation;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
 {
  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 62
Pankaj Wadhwa Avatar answered Oct 12 '22 19:10

Pankaj Wadhwa