4

I am using UIImagePickerController. I need guide my user to Setting -> Privacy to unlock the camera/photo access if they rejected it in the first place.

By default, UIImagePickerController will show:

without auth

But how about i want the message before presenting UIImagePickerController? How can i get the message that whether i have the access?

I want to claim that it is not an absolute duplicated question. AVCaptureDevice in this question detect permission of camera on ios only fixes the access to the camera, but the access to 'photo album' still cannot be detected.

duan
  • 8,515
  • 3
  • 48
  • 70
  • 1
    possible duplicate of [detect permission of camera on ios](http://stackoverflow.com/questions/20464631/detect-permission-of-camera-on-ios) – Tim Mar 14 '15 at 15:04
  • using `AVCaptureDevice` only fixes the access to the camera, not to the photo album. @Jeff – duan Mar 15 '15 at 12:31

2 Answers2

8

the question detect permission of camera on ios mentioned the class AVCaptureDevice, it can fix the authorization of Camera Usage.

I found the solution to the authorization of 'photo'. There is a new framework called Photos in IOS8 and a class PHPhotoLibrary.

This method can give an Alert:

PHPhotoLibrary.requestAuthorization({(status: PHAuthorizationStatus)in
    switch status{
    case .denied:
        break
    case .authorized:
        break
    default:
        break
    }
})

enter image description here

Just like when UIImagePickerController appears the first time.

and class func authorizationStatus() -> PHAuthorizationStatus can return the current authorization status of 'photo album'

duan
  • 8,515
  • 3
  • 48
  • 70
4

The AVCaptureDevice provides API for this.

        if (![[AVCaptureDevice  class] respondsToSelector:@selector(authorizationStatusForMediaType:)])
        {
            //Do something…
            break;
        }

        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        switch (authStatus)
        {
            case AVAuthorizationStatusAuthorized:
            case AVAuthorizationStatusRestricted:
            {
                //Do something…
                break;
            }
            case AVAuthorizationStatusDenied:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"App name" message:@"Appname does not have access to your camera. To enable access, go to iPhone Settings > AppName and turn on Camera." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];

                //Do something…
                break;
            }
            case AVAuthorizationStatusNotDetermined:
            {
                // not determined?!
                [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
                 {
                     if(granted)
                     {
                         dispatch_async(dispatch_get_main_queue(), ^
                         {
                             //Do something…
                         });
                     }
                     else
                     {
                         dispatch_async(dispatch_get_main_queue(), ^
                         {
                             //Do something…
                         });
                     }
                 }];
                break;
            }
            default:
                break;
        }
Nitheesh George
  • 1,357
  • 10
  • 13