我正在尝试下载文件并将该文件保存在 iOS 中。我正在使用ionic-native-file插件来实现这一目标。该文件已下载但我无法在设备中找到该文件。
filewrite = (): void => {
let transfer = this.fileTransfer.create();
let path = "";
let dir_name = 'Download';
let file_name = "Sample.pdf";
if (this.platform.is('ios')) {
this.platform.ready().then(() => {
path = this.file.documentsDirectory;
this.file.writeFile(path,file_name,this.pdfSrc).then((entry) => {
this.showAlert("download completed");
}, (error) => {
this.showAlert("Download Failed.");
}).catch(err=>{
this.showAlert("Download Failed catch.");
this.showAlert(err.message);
});
}
)
}
};
下载已完成的警报显示,下载的路径为:
file:///var/mobile/Containers/Data/Application/6DE22F30-5806-4393-830A-14C8A1F320BE/Library/Cloud/Sample.pdf
但我无法在设备中找到该位置。然后,我 google 并看到了这里。
cordova.file.documentsDirectory - 应用程序专用的文件,但对其他应用程序(e.g. Office 文件)有意义。请注意,对于 OSX,这是用户的~/Documents 目录。 (iOS,OSX)
所以,我实际上看不到该文件,因为它是应用程序的私有文件。然后我在同一个链接中看到:
所以,我尝试了我的 config.xml 中的两个偏好,但没有发生任何事情。
有没有办法下载文件 iOS 或 Dropbox 或其他任何地方?
1 回答
我也很难找到正确的目录,以便使用这个 cordova 插件保存到不同的平台上。我在 Android 上使用了
file.externalRootDirectory
,在 iOS 上使用了file.cacheDirectory
。正确的位置可能取决于您打算如何处理文件。在我的情况下,我只需要它存储 short-term 所以我可以使用用户的原生 PDF 阅读器打开它。