5

Setup:

I am using PHPickerViewController to allow the user to select photos. I've implemented the PHPickerViewControllerDelegate protocol method picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]). I am getting the itemProvider from the results array.

Problem:

I need to access the data for the selected image. There is a method on NSItemProvider called loadDataRepresentation(), which takes a type identifier string and should return the image data in its completion block.

When I call this method sometimes it returns data, sometimes it doesn't. I've tried this for the multiple registered type identifiers for each provider, and I'm seeing the same thing. Sometimes it will return JPEG data, but not HEIF, other times only HEIF, and sometimes it won't return any data at all. This is consistent in that the same photo exhibits the same result each time I try to load its data.

When there is no data I see the following error:

Upload preparation for claim D8C281B7-CCCE-4299-95BF-9355FCF340E4 completed with error: Error Domain=NSCocoaErrorDomain Code=260 "The file “7AB1AB3F-7643-45C1-9DD9-5F5642965C3A.jpeg” couldn’t be opened because there is no such file."

Is there something I need to do to the photo before attempting to load its data? Maybe I'm missing a step here? This happens for photos I took directly with my iPhone XR. I am not using iCloud Photos, all photos are on the device.

jbjohnny
  • 59
  • 2
  • It all depends on what types the NSItemProvider has registered with it, and what you ask it for. But you didn't show _any_ of your code, so it's impossible to help you. – matt Aug 13 '20 at 13:55
  • I created a simple dummy app that duplicates the problem. The problem doesn't occur when the list of types for the NSItemProvider is "public.jpeg" but does occur when NSItemProvider for a photo has types "public.jpeg" and "public.heic". Seems like it might be an iOS bug. – user2129643 Oct 09 '20 at 07:29

2 Answers2

1

"public.image" this identifier seems to be able to get all type of photos.

example : -

loadDataRepresentation(forTypeIdentifier: "public.image")

0

If you're getting this error in simulator it seems like it may be an OS bug, because doing a Device > Erase All Content and Settings.. to reset the simulator fixed this for me.

William T.
  • 12,831
  • 4
  • 56
  • 53