首页 > 解决方案 > ionic-native/file + ionic-native/http 下载不工作

问题描述

使用此答案中的代码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);
});

}

这是我尝试调用该方法时在 Xcode 控制台中得到的输出: 在此处输入图像描述

但是仍然没有下载任何内容。

更新:在真实设备上也不起作用

标签: iosionic-frameworkionic-nativeionic5ionic-native-http

解决方案


推荐阅读