Search code examples
iosnsnotificationcenterphotos

How to detect changes to PHAuthorizationStatus?


I need to detect changes to my app's permission to access Photos using PhotoKit on iOS 8. I can get the status with PHPhotoLibrary.authorizationStatus(), but I need to know when this status changes, so I can update the UI (which is asking them to change the permissions).

If the user launches the app, I check the authorizationStatus in viewDidLoad, then display the message if the status is .Denied or .Restricted. But if the user then goes to Settings and grants access, when they return to the app it is still showing that message. I need to handle those status changes - if it changes to .Authorized I need to remove the message and reload my collection view.

I couldn't find any notification I could subscribe to. How does one accomplish this?


Solution

  • I discovered when I run the app on a real device as opposed to debugging in the Simulator, when the user changes the photo access permission, the app seems to be terminated because when they return to the app it is not resumed where they were before. Because I request authorization in viewDidLoad for the first view controller, it properly handles the denied/restricted statuses.

    Note that if you're debugging the app in the Simulator when testing this, it will not terminate it. But if you stop running the app then try it, it will terminate it.