2

I had a code to request authorization that worked perfectly on iOS <= 13. When iOS 14 launched, PHPhotoLibrary.requestAutorization with Selected Photos stopped triggering the handler

PHPhotoLibrary.requestAuthorization { status in
            if status == .authorized {
                DispatchQueue.main.async {

Now the completion is not being called when the user selects Selected Photos. It starts working only after app restart, and more than that, it does not show limited library picker when it does work, so I have to call PHPhotoLibrary.shared().presentLimitedLibraryPicker manualy

I tried doing it the new way with

if #available(iOS 14, *) {
            PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
                switch status {
                case .authorized:
...
                case .limited:

but it doesn't get called here either I've been battling with this issue for days now, what could be the problem here? I have a feeling that something might be obstructing the views being called, but this code is being called with a press of a UIButton on a UIViewController inside a UITabBarViewController, so I have no idea.

1 Answers1

0

The limited library picker is displayed only once per session:

By default, the system automatically prompts the user to update their limited library selection once per app life cycle.

Also, application shouldn't asks access for photos library before will be relaunched, to check current access level you should use authorizationStatus(for:).
If status is equal to notDetermined, your application should asks access.
If status is limited, you can ask access to display the picker automatically to the user. Also, to allow the iOS to show the picker automatically, your application's plist should does not contain PHPhotoLibraryPreventAutomaticLimitedAccessAlert with true value.

If your application asked access before in current life cycle, the iOS, will no display the picker. Also, I think, the iOS contains some bug with the picker, and will not called the handler.

Here, you can find example of an application that uses new API.

Andrew Romanov
  • 4,774
  • 3
  • 25
  • 40