使用此答案中的代码https://stackoverflow.com/a/63585081/7751910并且无法使其正常工作。没有物理 ios 设备,所以使用 Xcode 模拟器。这是我使用 console.log() 的代码:
public downloadFileAndStore(fileUrl: string): void {
let filePath: string;
if (this.platform.is('ios')) {
filePath = this.file.documentsDirectory + this.getFileName(fileUrl);
} else { // for iOS use this.file.documentsDirectory
filePath = this.file.dataDirectory + this.getFileName(fileUrl);
}
this.nativeHTTP.downloadFile(fileUrl, {}, {}, filePath).then((response: any) => {
// prints 200
console.log('download success', response);
for (const key in response) {
if (Object.prototype.hasOwnProperty.call(response, key)) {
const element = response[key];
console.log(key);
console.log(element);
}
}
}).catch((err: any) => {
// prints 403
console.log('download error', err.status);
// prints Permission denied
console.log('download error', err.error);
});
}
但是仍然没有下载任何内容。
更新:在真实设备上也不起作用