1

Trying to write a picker for the avatar in my app and when PHAuthorizationStatus is .limited and the user already selected some photos in LimitedLibraryPicker, I'm trying to open the picker in this way

private func openPHPicker() {
        DispatchQueue.main.async { [weak self] in
            var phPickerConfig = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared())
            phPickerConfig.selectionLimit = 1
            let phPickerVC = PHPickerViewController(configuration: phPickerConfig)
            phPickerVC.delegate = self
            self?.present(phPickerVC, animated: true)
        }
     }

And the result is that PHPickerViewController opens and shows all of the photos not only accessible.

I want to open picker with only selected at LimitedLibraryPicker photos, only that for which I have access.

  • Initialize PHPickerConfiguration like `var phPickerConfig = PHPickerConfiguration()`, thats all! – Ganpat Nov 29 '22 at 16:52

1 Answers1

1

You don't need to request permission/authorisation when you use PHPickerViewController, especially for a trivial task as picking up an avatar image for your user. That being said, you can forget about the trouble of requesting permissions or displaying only the selected photos (with limited access).

Here you have some more information about the PHPickerViewController.

Apps don’t need to request photo library permission when using either class, so the sample app avoids requesting permission until it’s necessary. A camera app, photo editing app, or library browsing app needs to use much more of PhotoKit’s functionality, but an app that’s only setting a basic profile photo doesn’t need photo library permission. An app that only saves photos to the photo library can use the Add Photos Only permission level when requesting authorization.

To answer your question on how to display only the selected photos with PHPickerViewController: You can't! And you don't even need to, because the PHPickerViewController handles the access for you. This is the case for most apps that don't use PhotoKit and don't fetch the assets. I assume that's your case as well.

Also here they explain why you don't need access.

Edit: You might ask yourself: well, how does the user know that we don't actually need to request access to his photos? Well the answer is simple, he can see it in the Privacy & Security Settings/ Photos, in the Apps with one-off photo selection section. Something like this: enter image description here

MariaUngur
  • 52
  • 11