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

标签 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));
    });
}

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

请帮我解决这个问题。

最佳答案

您应该可以通过更新您的 Info.plist 来启用它。 .您需要添加两个键:
UIFileSharingEnabledLSSupportsOpeningDocumentsInPlace应该同时添加并设置为 YES .

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

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

    info.plist

    您可以阅读更多关于 LSSupportsOpeningDocumentsInPlace 的信息here

    In iOS 11 and later, if both this key and the UIFileSharingEnabled key are YES, the local file provider grants access to all the documents in the app’s Documents directory. These documents appear in the Files app, and in a document browser. Users can open and edit these document in place.



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

    关于react-native - React Native fs iOS 不显示文档目录中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54626359/

    相关文章:

    reactjs - 在选项卡导航器中调用堆栈函数会导致应用程序崩溃

    react-native - 任务队列 : Error with task: undefined is not an object (evaluating '_this.view._component.measureInWindow' ) in react native

    ios - 在 macOS Big Sur 上安装 react native 时出现 "Undefined symbol: protocol descriptor for Swift.ExpressibleByFloatLiteral"问题

    react-native - RNFS.exists() 总是返回 TRUE

    react-native - 为什么react-native-fs的readFile只读取文本文件的一部分?

    react-native - 如何在 react native 中获取文件夹大小和长度

    javascript - react native : iOS dictation unable to clear text input

    swift - Realm - RJSRealmDelegate.changes_available 断言(0)导致崩溃

    react-native - 使用 react-native-fs 将文件从 tmp 移动到文档

    reactjs - 如何在 React Native 中下载图像期间避免 "Excessive number of pending callbacks: 501"错误?