7

Considering user privacy I would like to implement a Limited Library Picker (introduced with iOS 14). Our app handles condition assessment of technical components by allowing the user to attach exactly one photo per component. For this we've been already using a conventional PHPickerViewController configured with a selectionLimit of 1. I expected the new Limited Library Picker to offer a similar PHPickerConfiguration option. However, this does not seem to be the case since its API does not expose a configurable PHPickerViewController object. Instead, the only way to present a Limited Library Picker is obviously to call the presentLimitedLibraryPicker method the from the PHPhotoLibrary singleton. As a result, I can always select multiple photos in the Limited Library view whereas the desired behaviour would be the selection of one photo maximum. Does anyone know how to achieve this behaviour with a Limited Library Picker?

In the following code example the conventional PHPickerViewController is presented if the users' PHAuthorizationStatus is .authorized (which works fine) and the Limited Library Picker if the PHAuthorizationStatus is .limited (lacking a selectionLimit):

        PHPhotoLibrary.requestAuthorization(for: .addOnly) { status in
            switch status {
            case .authorized:
                var configuration = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared())
                configuration.filter = .images
                configuration.selectionLimit = 1
                let phPicker = PHPickerViewController(configuration: configuration)
                phPicker.delegate = self as PHPickerViewControllerDelegate
                DispatchQueue.main.async {
                    self.view?.present(viewController: phPicker)
                }
            case .limited:
                PHPhotoLibrary.shared().register(self)
                DispatchQueue.main.async {
                    PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self)
                }
            default:
                //Ask for permission
        }
matthau
  • 71
  • 3
  • Hey, I am running into the same issue at the moment. Did you ever figure out how to limit the photo selection to only 1 photo? Thanks! – SuperFlyDan Aug 22 '22 at 12:22

0 Answers0