Error when loading images via PHPickerViewController

When using PHPickerViewController to load images from my photo library, several photos fail with:

Error Domain=NSItemProviderErrorDomain Code=-1200 "Could not coerce an item to class UIImage" UserInfo={NSLocalizedDescription=Could not coerce an item to class UIImage}

It appears to happen consistently on specific photos, even after restarting the device. I've set the PHPickerFilter to .images on the config, so I wouldn't expect casting to UIImage to be a problem.

In what scenario would casting to UIImage fail when the .image filter is set? There's nothing obviously different about the photos that receive this error. In fact, other photos taken as part of the same series work just fine.

Also, it's worth noting that these photos are part of a shared album.

Hello!

It is possible for there to be images in the Photo library that item provider cannot load as a UIImage, you can check if an item provider can load an object as a particular class with the canLoadObject(ofClass:) method.

When this is not the case for a particular image, you may need to take an alternative route to getting a UIImage of the asset in question. If you would like support on this, please request technical support because we will likely need specific details about the asset in question.

If your device has both iCloud Photos and Optimize Storage turned on, it's possible that some assets don't have local copies stored on your device. The Photos picker will try to download assets from iCloud and it will report an error if an asset can't be downloaded. For example, Photos may not have access to the internet (e.g. device not connected to Wi-Fi / device connected to Cellular but disabled Photos Cellular access). You can show an error alert to your users if you receive an error from the item provider.

Error when loading images via PHPickerViewController
 
 
Q