其他分享
首页 > 其他分享> > ionic3 fileTransfer.download ios无法下载也没有异常报出

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);
		});
	}
}

 

 

标签:loading,console,log,ios,private,ionic3,fileTransfer,end
来源: https://blog.csdn.net/ChaoYang0502/article/details/113988296