如何使最终用户可以访问由Cordova iOS APP动态生成/保存的文件? [英] How to make files dynamically generated/saved by Cordova iOS APP accessible to the end user?
问题描述
我正在使用 cordova-plugin-file
将一些数据图像保存到用户的iOS手机中.
I'm using the cordova-plugin-file
to save some data image to the user's iOS phone.
saveBlobAsImageFile(folderpath, filename, blob) {
const onError = function(msg) {
// handles error
}
window.resolveLocalFileSystemURL(folderpath, function(dir) {
console.log("Access to the directory granted");
dir.getFile(filename, { create: true }, function(file) {
console.log("File created")
file.createWriter(function(fileWriter) {
fileWriter.write(blob);
console.log("Written file")
}, onError)
}, onError)
}, onError)
}
对于 folderpath
,我尝试了所有这5个选项:
for the folderpath
, I tried all of these 5 options:
let folderpath = cordova.file.syncedDataDirectory;
let folderpath1 = cordova.file.documentsDirectory;
let folderpath2 = cordova.file.dataDirectory;
let folderpath3 = cordova.file.cacheDirectory;
let folderpath4 = cordova.file.tempDirectory;
运行功能 saveBlobAsImageFile
后,日志显示写入成功,但是当我进入模拟器/iPhone中的文件或库时,找不到任何保存的文件.
After running the function saveBlobAsImageFile
, the log shows the successful writing, but when I go to Files or Library in my simulator/iPhone, I cannot found any saved file.
更新:当我在模拟器中运行时,单击保存"后,我发现文件保存在以下文件夹中:
Update: When I run in simulator, after clicking save, I found the file saved in these folders:
file:///Users/ngoctuan001/Library/Developer/CoreSimulator/Devices/2964FE69-A5FE-4516-B8F1-C45488DBE2B5/data/Containers/Data/Application/1EF9FF0C-903E-481F-87A0-9A1CEDA4DE5D/Library/Cloud/
file:///Users/ngoctuan001/Library/Developer/CoreSimulator/Devices/2964FE69-A5FE-4516-B8F1-C45488DBE2B5/data/Containers/Data/Application/1EF9FF0C-903E-481F-87A0-9A1CEDA4DE5D/Documents/
file:///Users/ngoctuan001/Library/Developer/CoreSimulator/Devices/2964FE69-A5FE-4516-B8F1-C45488DBE2B5/data/Containers/Data/Application/1EF9FF0C-903E-481F-87A0-9A1CEDA4DE5D/Library/NoCloud/
file:///Users/ngoctuan001/Library/Developer/CoreSimulator/Devices/2964FE69-A5FE-4516-B8F1-C45488DBE2B5/data/Containers/Data/Application/1EF9FF0C-903E-481F-87A0-9A1CEDA4DE5D/Library/Caches/
但是,当我转到模拟器文件和库时,找不到这些图像.
However, when I go to the simulator files and library, these images are not found.
如何使iOS Cordova APP通过库自动使最终用户访问动态生成的文件?
推荐答案
如果在 UIFileSharingEnabled
, LSSupportsOpeningDocumentsInPlace
, UISupportsDocumentBrowser
中全部添加为是"plist文件,您的应用文件将对iOS资源管理器可见.主要来源是此处.
If you add UIFileSharingEnabled
, LSSupportsOpeningDocumentsInPlace
, UISupportsDocumentBrowser
all as YES on plist file, your app files will be visible to iOS Explorer. The main source is here.
因此,您可以编辑 config.xml
,并将这些条目添加到<平台名称="ios">
Thus you can edit your config.xml
adding these entries inside <platform name="ios">
<edit-config target="UIFileSharingEnabled" file="*-Info.plist" mode="merge">
<true/>
</edit-config>
<edit-config target="LSSupportsOpeningDocumentsInPlace" file="*-Info.plist" mode="merge">
<true/>
</edit-config>
<edit-config target="UISupportsDocumentBrowser" file="*-Info.plist" mode="merge">
<true/>
</edit-config>
这篇关于如何使最终用户可以访问由Cordova iOS APP动态生成/保存的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!