Search code examples
iosuiimagepickercontroller

How can I get the authorization status to Photo/Camera on IOS?


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.


Solution

  • 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'