Calling loadFileRepresentationForTypeIdentifier
sometimes returns an empty file, the URL params is filled with a path where a file exists, however it contains empty content.
My app is released on the store and this error happens 1.5% of the time my users pick an image / video from their gallery using the UIImagePickerControllerDelegate.
I was able to reproduce this bug and here is a screenshot of XCode in debug mode so you can see that the file is empty right after calling loadFileRepresentationForTypeIdentifier
I'm using XCode 14.3.1, a real iPhone 12 with iOS 16.3.1 and coding in Objective-C.
Step to repro :
1- Capture a live photo with your device
2- Pick this photo from your gallery using UIImagePickerControllerDelegate
-> didFinishPicking
3- Grab the item provider and call provider loadFileRepresentationForTypeIdentifier:@"public.jpeg"
4- Inside the completion handler check the file size of the URL provided in the parameters
It is 1.5% repro, so to repro in local I had to take hundreds of live photos. But with patience, it happens and you can debug.
Note: Calling a second time loadFileRepresentationForTypeIdentifier:@"public.jpeg"
inside the completionHandler
returns a URL pointing to a real file with existing content, thus there might be some race conditions somewhere.
Do you have any workarounds?