我正在做一个本地项目。我需要将捕获的图像存储在自定义文件夹中。
为此,我使用了react本机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 . 您需要添加两个键:
Info.plist
UIFileSharingEnabled 和 LSSupportsOpeningDocumentsInPlace 应同时添加和设置为 YES .
UIFileSharingEnabled
LSSupportsOpeningDocumentsInPlace
YES
已启用ui文件共享
LSSupportsOpeningDocumentsInPlace支持
这将允许您 DocumentsDirectory 在iTunes中打开,它还应允许您通过 Files 应用。
DocumentsDirectory
Files
你可以阅读更多关于 LSSupportsOpeningDocumentsInPlace支持 here
在iOS 11及更高版本中,如果此密钥和 已启用ui文件共享 钥匙 是 对 ,本地文件提供程序授予对中所有文档的访问权限。 应用程序 Documents 目录。这些文档出现在 文件夹 在文档浏览器中。用户可以打开和编辑这些文档 就位。
对
Documents
文件夹
注意 任何 保存在中的项目 文件 目录将可访问。
文件