【问题标题】:React native fs iOS not showing files in the document directory反应原生 fs iOS 不显示文档目录中的文件
【发布时间】:2021-06-06 02:58:54
【问题描述】:

我正在开发一个 react native 项目。我需要将捕获的图像存储在自定义文件夹中。

我为此使用 react native fs 库。我可以在所需目录中创建图像,但无法在我的 iphone 文件目录中看到这些图像。

这是我用来存储图像的代码。

 async moveAttachment(capturedImagePath) {

    $filePathDir = `${RNFS.DocumentDirectoryPath}/myapp/myfilename`;
    $filePath = `${$filePathDir }/myfilename.png`;
    return new Promise((resolve, reject) => {
        RNFS.mkdir(filePathDir)
        .then(() => {
            RNFS.moveFile(capturedImagePath, filePath )
            .then(() => resolve(dirPictures))
            .catch(error => reject(error));
        })
        .catch(err => reject(err));
    });
}

我可以在模拟器的文档目录中看到图像,但在 iPhone > 文件目录中看不到。

请帮我解决这个问题。

【问题讨论】:

  • 该文件将存储在应用程序的文档目录中。你怎么检查它不存在?因为如果您正在查看 Files 应用程序,您不会在那里看到它。
  • @Andrew 我需要将文件存储在本地存储中,这样我就可以在不使用我的应用程序的情况下访问它们。

标签: react-native react-native-fs


【解决方案1】:

您应该可以通过更新您的Info.plist 来启用它。您需要添加两个键:

UIFileSharingEnabledLSSupportsOpeningDocumentsInPlace 都应添加并设置为 YES

  • UIFileSharingEnabled: 应用支持iTunes文件分享
  • LSSupportsOpeningDocumentsInPlace: 支持原地打开文档

这将允许您在 iTunes 中打开您的 DocumentsDirectory,它还应该允许您通过 Files 应用程序共享您的文件。

你可以阅读更多关于LSSupportsOpeningDocumentsInPlacehere

在 iOS 11 及更高版本中,如果此键和 UIFileSharingEnabled 键 是YES,本地文件提供者授予访问所有文件的权限 应用程序的Documents 目录。这些文件出现在Files 应用程序,并在文档浏览器中。用户可以打开和编辑这些文档 到位。

请注意,您保存在Documents 目录中的任何项都可以访问。

【讨论】:

    猜你喜欢
    • 2018-09-06
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2014-07-20
    • 2020-04-09
    相关资源
    最近更新 更多