React Native fs iOS 不显示文档目录中的文件 [英] React native fs iOS not showing files in the document directory

查看:43
本文介绍了React Native fs iOS 不显示文档目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个 React Native 项目.我需要将捕获的图像存储在自定义文件夹中.

I am working on a react native project. I need to store the captured images in the custom folder.

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

I am using react native fs library for that. I am able to create the image in the desired directory but I am not able to see those images in my iphones' file directory.

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

Here is my code I am using to store the images.

 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 > 文件目录中看不到.

I am able to see the image in my simulator's document directory but not able to see in the iPhone > files directory.

请帮我解决这个问题.

推荐答案

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

You should be able to enable it by updating your Info.plist. You need to add two keys:

UIFileSharingEnabledLSSupportsOpeningDocumentsInPlace 都应该添加并设置为 YES.

UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace should both be added and set to YES.

  • UIFileSharingEnabled:应用程序支持iTunes文件共享
  • LSSupportsOpeningDocumentsInPlace:支持就地打开文档
  • UIFileSharingEnabled: Application supports iTunes file sharing
  • LSSupportsOpeningDocumentsInPlace: Supports opening documents in place

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

This will allow your DocumentsDirectory to be opened in iTunes and it should also allow you to share your files via the Files application.

您可以阅读有关 LSSupportsOpeningDocumentsInPlace 的更多信息 这里

You can read more about LSSupportsOpeningDocumentsInPlace here

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

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 目录中的任何项目都可以访问.

Note that any item you save in the Documents directory will be accessible.

这篇关于React Native fs iOS 不显示文档目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆