Why am i getting an error when trying to load a HEIC photo from PHPickerResult?

In Xcode 12 beta 4 i could load both a jpeg and HEIC image using itemProvider.loadObject(ofClass: UIImage.self).

But in beta 5 when using it with a HEIC file i get "Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.jpeg""

Is this by design?

Also, itemProvider.canLoadObject(ofClass: UIImage.self) still returns true for both jpeg and HEIC files.
itemProvider.loadObject(ofClass: UIImage.self) should work with any image type (HEIC images may be converted to JEPG images on the fly).

It would be great if you can provide us some additional information so we can further investigate this issue. You can also file a Feedback request with a sample project/code or sysdiagnose.
  • Does it only reproduce using simulators? We have a known issue causing HEIF images not being returned correctly, but it only affects simulators (63426347).

  • Does it only reproduce with a particular asset?

  • What's your configuration.preferredAssetRepresentationMode?

itemProvider.loadObject(ofClass: UIImage.self) should work with any image type (HEIC images may be converted to JEPG images on the fly).

And what if you need the original image data? Is there a way to not allow HEIC images to be converted to JPEG images?

And what if you need the original image data? Is there a way to not allow HEIC images to be converted to JPEG images?

You can use loadFileRepresentation(forTypeIdentifier:) and pass in the UTI you want. For UTIs that have multiple different representations (e.g. public.image), set preferredAssetRepresentationMode to .current.
Hello!

Got it working now by using .itemProvider.loadDataRepresentation(forTypeIdentifier: "public.image") and setting configuration.preferredAssetRepresentationMode to .current

.itemProvider.loadObject(ofClass: UIImage.self) still does not work as the returned image is always nil for a HEIC file.

However, now in beta 6 i don't get the old error message but rather:

Code Block
[claims] Upload preparation for claim 2E4CFF7E-C854-4B56-BBC5-F64CBAE75B5A completed with error: Error Domain=NSCocoaErrorDomain Code=260 "The file “version=1&uuid=C6966245-F3C9-4777-8C0B-309FB71EE995&mode=compatible.jpeg” couldn’t be opened because there is no such file."

So perhaps related to issue (64630315)?

This is only in the simulator as i do not have my beta device with me but will try to verify it later.

And yes from what i can see it affects all HEIC images.


Thanks! It sounds like 63426347 which should only affect the simulator. But please let us know if it's not the case!

It's been 1 year since the problem was not solved in the simulator, and anyone who has only one mac (which is not easy to acquire in Brazil) is screwed.

Why am i getting an error when trying to load a HEIC photo from PHPickerResult?
 
 
Q