Support returning ph:// from MediaLibrary APIs
See original GitHub issueSummary
On iOS Assets Library API is depreacted: https://developer.apple.com/documentation/assetslibrary. The MediaLibrary still uses the old assets-library://
schema. It is incompatible with a few APIs like the sharing API and the FaceDetection API.
Found this comment here that alerted me to that: https://github.com/react-native-cameraroll/react-native-cameraroll/blob/master/ios/RNCAssetsLibraryRequestHandler.m#L68.
After a Twitter conversation we found these lines responsible: https://github.com/expo/expo/blob/fffbdb3161449764087dfa6d555ad1f88eb86dfe/packages/expo-media-library/ios/EXMediaLibrary/EXMediaLibrary.m#L920-L926
I was quite confused about it as you can see here: https://stackoverflow.com/questions/67422493/getting-a-filesystem-uri-from-assets-in-expo-rn.
The only workaround I found from the JS API was to copy assets to a cache directory. This is less than ideal as it slows things down quite a bit.
Managed or bare workflow? If you have ios/
or android/
directories in your project, the answer is bare!
managed
What platform(s) does this occur on?
iOS
SDK Version (managed workflow only)
41.0
Environment
N/A
Reproducible demo or steps to reproduce from a blank project
N/A
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (1 by maintainers)
Top GitHub Comments
hey there - I’ve been looking into this issue a bit today - I think the method you might want to use here is
MediaLibrary.getAssetInfoAsync(asset)
which will return alocalUri
containing thefile://
url that can be used with other APIs. This method obtains a local image url viaPHAsset.requestContentEditingInputWithOptions
async blockAn alternative, as you have noted in SO, would be using something like
PHImageManager requestImageDataForAsset
after obtaining the PHAsset - although this is not done by the MediaLibrary module so you’d have to write your own implementation for that.In either case, updating the url here does not immediately solve any integration issues that you’ve described, as most of these APIs require the
file://
localUri from aPHAsset
, something that needs to be asynchronously fetched one way or another. That being said I think it’s safe to update theasset-library://
toph://
url and I’ll try and get this into SDK 43In the meantime, the an
asset.id
can be used to generate the sameph://
url like so:I ended up just rewriting the
asset-library://
URIs toph://
URIs by grabbing the ID from the former’s query parameters & appending it to the latter.I did have to install an SDWebImage plugin to support
ph://
URIs though.