ionic3 fileTransfer.download ios无法下载也没有异常报出

 安卓端没有问题,但在IOS系统中点击下载没有反应,也没有任何异常,解决方法:fileTransfer在调用时再实例化即可;

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers: [FileTransfer, File]
})

export class HomePage {
	  private fileTransfer: FileTransferObject;
	  ...
	  ...

	constructor(public navCtrl: NavController, private transfer: FileTransfer, private file: File, private alertCtrl: AlertController, private platform: Platform) {
		...
	}

	downloadFile() {
		  // using a local constant is also a valid alternative,
		  // the important thing is to instantiate the object at this time
		  // const fileTransfer: FileTransferObject = this.transfer.create();
		  this.fileTransfer = this.transfer.create();
		  this.fileTransfer.download(url,  nativeUrl,true).then((entry) => {
		  console.log(nativeUrl);
		  let fileType = fileName.substr(fileName.lastIndexOf(".")+1);
		  // entry.nativeURL 是上面那个插件文件下载后的保存路径
		  this.loading_end();
		  this.fileOpener.open(nativeUrl, this.getFileMimeType(fileType))
			.then(() => {
			  console.log('打开成功');
			  this.loading_end();
			})
			.catch(err => {
			  console.log(err);
			  this.loading_end();
			  this.showAlertFirst(err,null);
			});
		}, (error) => {
		  this.showAlertFirst('下载失败',null);
		  this.loading_end();
		  console.log(error);
		});
	}
}

 

 

上一篇:构建结构化NLP服务(loading...)


下一篇:brew mac osx 上软件包管理工具