【问题标题】:Getting a filesystem URI from assets in Expo/RN从 Expo/RN 中的资产获取文件系统 URI
【发布时间】:2021-05-06 16:40:33
【问题描述】:

在 iOS 上,使用 MediaLibrary.getAssetsAsync() 会返回带有 assets-library://.... uri 的资产。

但是很多 Expo/ReactNative API 需要 file:// uri,例如face detector 模块和sharing module

为了解决这个问题,我最终只是使用FileSystem.copyAsset() 将资产复制到应用程序缓存目录。有没有更好的办法?为什么需要这样做?

const localUri = FileSystem.copyAsset(FileSystem.cacheDirectory + '/' + asset.filename)

【问题讨论】:

    标签: javascript ios react-native expo


    【解决方案1】:

    assets-library:// 似乎是一个较旧的 iOS API,现已弃用。您可以在此处找到参考:https://developer.apple.com/documentation/assetslibrary。

    Expo SDK 41.0 的实现依赖于这个旧库。我已经 opened an issue 将其升级为使用 PhotoKit。

    在裸流程中,您可以使用 swift 在本机模块中使用它:

    let oldUrl = URL(string: imageUri)!
    let assets = PHAsset.fetchAssets(withALAssetURLs: [oldUrl], options: nil)
    

    这将为您提供一个 Photokit 资源,然后您可以使用 PHManager 根据您需要的大小获取图像表示。

    【讨论】:

      猜你喜欢
      • 2011-06-16
      • 1970-01-01
      • 2022-11-19
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      相关资源
      最近更新 更多