I even tested all of the objects that are listed as implementers of the NSItemProviderReading protocol, and none of them worked, including the AVURLAsset, and AVFragmentedAsset which seemed like the most likely candidates.
In the demo video it mentions that you can also get access to video data but there is no clear way to do that.
I have found a few solutions floating around online that show them using the loadItem(forType: ) function as follows.
Code Block itemProvider.loadItem(forTypeIdentifier: "com.apple.quicktime-movie", options: nil)
Then in the response they can get a URL and use the video that way. However, when I use that method to get the URL I then try and get the video data using Data(contentsOf: URL) I'm getting the following error.
Code Block Error Domain=NSCocoaErrorDomain Code=260 "The file “version=1&uuid=FAKEGUID-FAKE-GUID-FAKE-GUIDFAKEGUID&mode=compatible.mov” couldn’t be opened because there is no such file."
(Note: I replaced the actual guid if you couldn't tell)Also, a side note, I don't really like getting the Item from the typeIdentifier because it requires me to check for other cases as well, .mp4 vs .mov extensions for example.
I'm able to get the video data that I need by using the PHAsset fetchAssetsWithLocalIdentifiers route, but I would prefer to avoid that route because it involves getting permissions and dealing with limited libraries. I don't think that my use case requires me to get the PHAsset but I do need access to the video Data.
Is there a straightforward way to get video data using only the PHPiker that I'm missing? Or is it necessary to use PhotoKit to get that data?
Thank you in advance for the help!
Use itemProvider.loadFileRepresentation instead of itemProvider.loadItem for large files like videos. Please make sure you copy the file (it will create an APFS clone so the copy operation will be really fast) before the completion handler returns.
You can use the umbrella UTType.movie.identifier ("public.movie") UTI to get all videos. Optional: set preferredAssetRepresentationMode to .current to avoid transcoding if your app supports all possible encodings or don't care about the encoding format.