1

I've hit "cancel" on a popup that asks permission for the photo library in the app I made. This comes from something I didn't make, but from the OS.

Now I need a fallback if the user tries to hit the photo library button again. The authorization status is denied. I proved by checking it this way:

    let status = PHPhotoLibrary.authorizationStatus()

    switch status {
    case .authorized:
        print("authorized")

    case .denied:
        print("denied") // it is denied

    case .notDetermined:
        print("notDetermined")

    case .restricted:
        print("restricted")

    }

How do I present a popup asking for permission to the photo library again? I've looked everywhere and cannot find anything that works.

I was hoping it was something like this, but PHPhotoLibrary has no member "requestAccess":

PHPhotoLibrary.requestAccess(for: ???) { response in
    if response {
        //access granted
    } else {

    }
}
Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90

1 Answers1

6

If the status be on . notDetermined, so the app automatically shows the alert to the user, but if the status was on .restricted or denied you cannot do anything to ask user again for the access to the photos like the original one, but you can make a custom alert and ask user to give you access to the photos and if user accepted your request, lead the user to the setting and ask him to enable your access manually!

  • Just a note: It is denied, not restricted. How do I make a custom alert for permission and have actually set the permission based on the user's response? – Chewie The Chorkie May 01 '18 at 19:00
  • I updated the answer. the answer is the same. Apple does not allow the developer to ask for access more than one time. So the only way is that I said in the above – Seyed Samad Gholamzadeh May 01 '18 at 19:05
  • I see, so I need to have a section for Settings for this app. Wow this is way more involved than I thought. Thank you for the information. – Chewie The Chorkie May 01 '18 at 19:09
  • 1
    In case that helps, if you want to redirect your user to settings, you can do it by executing `UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!, options: [:], completionHandler: nil)` – Julien Perrenoud May 01 '18 at 21:32
  • Which library is it? `Use of unresolved identifier 'PHPhotoLibrary'` – Amg91 Dec 14 '18 at 00:44