PHPhotoLibrary requestAuthorization, not requesting

bauerMusic picture bauerMusic · Jan 29, 2016 · Viewed 9.4k times · Source

For testing, I was trying to recreate the system 'Requesting Access' popup experience.

Update:
Under iOS 11, after deleting the App, the system popup will be displayed again.


(previous question)

First time the App run (and the only time), the system popup showed, requesting access. After that, not even deleting the App and restarting the device will trigger that popup again.

In other words, the device 'remembers' the user request and there's no way to reset it.

Here's the code:

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

    switch (status) {
        case PHAuthorizationStatusAuthorized:
            NSLog(@"PHAuthorizationStatusAuthorized");
            break;

        case PHAuthorizationStatusDenied:
            NSLog(@"PHAuthorizationStatusDenied");
            break;
        case PHAuthorizationStatusNotDetermined:
            NSLog(@"PHAuthorizationStatusNotDetermined");
            break;
        case PHAuthorizationStatusRestricted:
            NSLog(@"PHAuthorizationStatusRestricted");
            break;
    }

}];

When access is off in settings, it keeps printing "PHAuthorizationStatusDenied". But does not present any popup. Returns immediately.

It was suggested to add 'Bundle display name' to the plist. Tried it to no avail, with empty value, $(PRODUCT_NAME), and different strings.

Cleaned project, deleted DrivedData (and delete App from simulator every time). No luck.

More info:

The Apple sample code "SamplePhotosApp", is crashing once you turn off photo access in the Settings.

Answer

bauerMusic picture bauerMusic · Jan 29, 2016

After further reading, this seems to be by design.

From Apple:

This method always returns immediately. If the user has previously granted or denied photo library access permission, it executes the handler block when called; otherwise, it displays an alert and executes the block only after the user has responded to the alert.

Saying 'This method always returns immediately' if user was prompt once. After that it will not show the request again. Seems to be no way (but some custom message) to use the system message again.