PHPicker: a new system-provided picker screen that gives you access to photos and videos from the user’s photo library.
It’s recommended that you use this picker instead of building your own custom photo selection UI.
New version includes:
a new design and new easy to use API
an integrated search
easy multi-select
zoom gesture
PHPicker is private by default:
the picker screen runs out of process and talks to the app via XPC
your app has no direct access to the photos library
it doesn’t need to get photo library permission (don’t ask for it unless you really need it)
you only get selected photos and videos in response
PHPicker is not a name of a single class, but a set of classes that work together.
Elements of the API
PHPickerConfiguration – lets you specify limits and filters:
selectionLimit– number of items that can be selected (1 by default, 0 = unlimited)filter– e.g..imagesor.any(of: [.videos, .livePhotos])
PHPickerViewController – the main view controller handling the picker:
the picker doesn’t dismiss itself automatically, call
picker.dismiss(animated:)when you get the response
PHPickerViewControllerDelegate – delegate for the picker:
PHPickerResult – an array of these objects is passed to the app in response
get
itemProviderfrom the resultcheck
itemProvider.canLoadObject(ofClass: UIImage.self)get the image via
itemProvider.loadObject(ofClass: UIImage.self) { … }
You can normally extract picked photos from PHPickerResult item providers without touching the PHPhotoLibrary at all, but if you do need to access the photo library anyway, then pass it to PHPickerConfiguration.init and get assetIdentifier references from the picker results.
If you use PHPicker with photo library access and you only got limited access to a subset of photos, then:
PHPicker will still let the user choose photos from their whole library
but the selection you have direct access to will not be extended by what they choose in the picker
The photo library APIs from UIImagePickerController are deprecated.
Full blog post here: https://mackuba.eu/2020/07/07/photo-library-changes-ios-14/
