React Native fs iOS 不显示文档目录中的文件

Pan*_*wal 4 react-native react-native-fs

我正在做一个 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));
    });
}
Run Code Online (Sandbox Code Playgroud)

我能够在模拟器的文档目录中看到图像,但无法在 iPhone > 文件目录中看到。

请帮我解决这个问题。

And*_*rew 15

您应该能够通过更新您的Info.plist. 您需要添加两个键:

UIFileSharingEnabled并且LSSupportsOpeningDocumentsInPlace都应该添加并设置为YES.

  • UIFileSharingEnabled:应用程序支持iTunes文件共享
  • LSSupportsOpeningDocumentsInPlace: 支持打开文件到位

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

信息.plist

你可以在这里阅读更多LSSupportsOpeningDocumentsInPlace

在 iOS 11 及更高版本中,如果此密钥和UIFileSharingEnabled密钥都是YES,则本地文件提供程序授予对应用程序Documents目录中所有文档的访问权限。这些文档显示在Files 应用程序和文档浏览器中。用户可以就地打开和编辑这些文档。

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