jbjohnny
jbjohnny

Reputation: 59

iOS 14 NSItemProvider loadDataRepresentation() returns nil data for specified types

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.

Upvotes: 5

Views: 3048

Answers (2)

William T.
William T.

Reputation: 14361

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.

Upvotes: 0

jayesh chaudhari
jayesh chaudhari

Reputation: 99

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

example : -

loadDataRepresentation(forTypeIdentifier: "public.image")

Upvotes: 1

Related Questions