PHPicker fails to load RAW images

We observed that the PHPicker is unable to load RAW images captured on an iPhone in some scenarios. And it is also somehow related to iCloud.

Here is the setup:

The PHPickerViewController is configured with preferredAssetRepresentationMode = .current to avoid transcoding.

The image is loaded from the item provider like this:

if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeImage) {
    itemProvider.loadFileRepresentation(forTypeIdentifier: kUTTypeImage) { url, error in
        // work
    }
}

This usually works, also for RAW images. However, when trying to load a RAW image that has just been captured with the iPhone, the loading fails with the following errors on the console:

[claims] 43A5D3B2-84CD-488D-B9E4-19F9ED5F39EB grantAccessClaim reply is an error: Error Domain=NSCocoaErrorDomain Code=4097 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x2804a8e70 {Error Domain=NSCocoaErrorDomain Code=4097 "connection from pid 19420 on anonymousListener or serviceListener" UserInfo={NSDebugDescription=connection from pid 19420 on anonymousListener or serviceListener}}}

Error copying file type public.image. Error: Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.image" UserInfo={NSLocalizedDescription=Cannot load representation of type public.image, NSUnderlyingError=0x280480540 {Error Domain=NSCocoaErrorDomain Code=4097 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x2804a8e70 {Error Domain=NSCocoaErrorDomain Code=4097 "connection from pid 19420 on anonymousListener or serviceListener" UserInfo={NSDebugDescription=connection from pid 19420 on anonymousListener or serviceListener}}}}}

We observed that on some devices, loading the image will actually work after a short time (~30 sec), but on others it will always fail.

We think it is related to iCloud Photos: On the device that has iCloud Photos sync enabled, the picker is able to load the image right after it was synced to the cloud. On devices that don't sync the image, loading always fails. It seems that the sync process is doing some processing (?) of the image that will later enable the picker to load it successfully, but that's just guessing.

Additional observations:

  • This seems to only occur for images that were taken with the stock Camera app. When using Halide to capture RAW (either ProRAW or RAW), the Picker is able to load the image.
  • When trying to load the image as kUTTypeRawImage instead of kUTTypeImage, it also fails.
  • The picker also can't load RAW images that were AirDroped from another device, unless it synced to iCloud first.
  • This is reproducable using the Selecting Photos and Videos in iOS sample code project.
  • We observed this happening in other apps that use the PHPicker, not just ours.

Is this a bug, or is there something that we are missing?

Also filed as FB12042331. Thanks for looking into this!

Hello!

This is tracked by 98346370 and should be resolved in latest iOS beta.

Thank you for the very well-written feedback report. This does seem like a bug to me. We'll make sure the right engineer takes a look at the report.

Do you mind posting the FB12042331 to https://openradar.appspot.com/ for visibility?

I'm also seeing a similar behavior when trying to load the file representation using public.item UTI for Live Photos that were just taken or were selected and probably downloaded from icloud. If I try again the same images on a second or third time they seem to be loading just fine. If I use public.image it works just fine, note that it is on iOS 17 public beta. Exception:

Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.item" UserInfo={NSLocalizedDescription=Cannot load representation of type public.item, NSUnderlyingError=0x281b031e0 {Error Domain=NSCocoaErrorDomain Code=4097 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x281a32bb0 {Error Domain=NSCocoaErrorDomain Code=4097 "connection from pid 1217 on anonymousListener or serviceListener" UserInfo={NSDebugDescription=connection from pid 1217 on anonymousListener or serviceListener}}}}}
PHPicker fails to load RAW images
 
 
Q