6

Is there a way to show the user's current photo selections when presenting a PHPickerViewController manually? For example, when using the following code the picker doesn't show any of the user's currently selected photos.

 var pickerConfig = PHPickerConfiguration()
 pickerConfig.selectionLimit = 0
 pickerConfig.filter = .any(of: [.images])
            
 let imagePicker = PHPickerViewController(configuration: pickerConfig)
 imagePicker.delegate = self

 // When presented, the user's current selected photos are empty, nothing is selected
 viewController.present(imagePicker, animated: true)

However, if I use Apple's built in presentLimitedLibraryPicker function it does show the user's current photo selections:

// This does show the user's current selections
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from controller: self)

Is there a way to get this behavior without using presentLimitedLibraryPicker?

JKo
  • 1,260
  • 1
  • 10
  • 18
  • Try increasing the `selectionLimit` to something greater than 0 – aheze Sep 28 '20 at 20:49
  • 1
    What are "current selections" in this context? You mean what the user is selecting right now in the picker after you present it? Or what the user selected before? Or what? – matt Sep 28 '20 at 20:50
  • @matt I'm referring to photos that the user has selected before. So if they have 20 photos selected and I present the PHPickerViewController, none of those selections are showing up. – JKo Sep 28 '20 at 20:52
  • If they have 20 photos selected where before? When before? PHPickerViewController has no memory, it doesn't know anything about what happened "before". – matt Sep 28 '20 at 20:54
  • @aheze Thanks for the suggestion but I've tried that and it doesn't work. A selection limit of 0 on the PHPickerConfiguration means the maximum supported by the system. – JKo Sep 28 '20 at 20:54
  • @JKoko wait I thought you meant the photos aren't highlighted when you press them -- "the picker doesn't show any current selections" – aheze Sep 28 '20 at 20:58
  • @matt For my specific use case, the user selects these photos on the app's first launch. If they select limited photo library access, the system presents the photo picker. In my Settings screen, I give the user the option to add/remove photos later on if they want, but when I present the picker manually all of the selections are missing. When I use the presentLimitedLibraryPicker API, the selections show as expected. – JKo Sep 28 '20 at 21:05
  • But changing what photos can be accessed under limited access is not the job of the PHPicker. That is the job of the `presentLimitedLibraryPicker` picker. – matt Sep 28 '20 at 21:07
  • @matt That is true, I am thinking about this incorrectly then. I'll need to stick with `presentLimitedLibraryPicker` and utilize the PHPhotoLibraryChangeObserver to listen for updates to the selections. – JKo Sep 28 '20 at 21:18
  • Correct-a-mundo. – matt Sep 28 '20 at 21:25
  • If you just need one-off access to those photos you should just stick with the PHPicker instead, so that users don't need to grant any permissions at all. If you manage a list of access-granted pictures, then you need to handle the limited access permission and show the limited picker by tapping on some UI element to "refresh" content, then listen to the notification to update your content. – Rafael Nobre Oct 07 '20 at 19:37
  • 1
    Mind to share the answer @JKoko ? – Nizzam Oct 15 '20 at 03:37

0 Answers0