我正在做一个 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
来启用它。 .您需要添加两个键:UIFileSharingEnabled
和 LSSupportsOpeningDocumentsInPlace
应该同时添加并设置为 YES
.
UIFileSharingEnabled
: 应用程序支持iTunes文件共享LSSupportsOpeningDocumentsInPlace
: 支持原地打开文件这将允许您的
DocumentsDirectory
要在 iTunes 中打开,它还应该允许您通过 Files
共享您的文件应用。您可以阅读更多关于
LSSupportsOpeningDocumentsInPlace
的信息hereIn iOS 11 and later, if both this key and the
UIFileSharingEnabled
key areYES
, the local file provider grants access to all the documents in the app’sDocuments
directory. These documents appear in theFiles
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/