I'm using PHPickerViewController
. In the delegate method, I load the images like this:
results.forEach {
if $0.itemProvider.canLoadObject(ofClass: UIImage.self) {
$0.itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, error in
guard let image = image as? UIImage else { return }
}
}
}
This code works on iOS 12~16, but on iOS 17, from time to time, the itemProvider.canLoadObject
method straight up returns false
.
At first, I found this issue on iOS 17.0.3, and I upgraded the OS, and it's gone. But later bug reports suggest that it also appears on iOS 17.1.1.
I haven't found much discussion about it though. I did find some similar issues:
- https://developer.apple.com/forums/thread/739161
- https://github.com/ionic-team/capacitor-plugins/issues/1807#issuecomment-1781403132
The later one is on ionic but it appears to be the same. In that thread, there was a workaround.
I didn't test it since the PHAsset.fetchAssets
code in it would require photo library permission. This could break our app's user experience, since the picker itself wouldn't require any permission to popup and it shows all the photos, but the PHAsset would ask for it when you finished the selection. What's even worse is when we have limited access to the photo library, we might not even be able to load the photo that's selected by the user but is limited to the app.
Upgraded the OS version from 17.0.3 to 17.1, and it was gone. But later found the same issue on iOS 17.1.1.
Turns out
loadObject(ofClass: UIImage.self)
won't work for RAW photos on iOS 17.Again, this does work on iOS 16.
I ended up changing my code to this: