我正在使用Ionic 3版本和Cordova将文件从URL下载到特定的文件夹。在Android上这对我来说很好用,因为可以在特定文件夹中下载文件,但是如果不下载IOS设备,则文件不会下载。
//download file based on file type i.e. URL,dataURL,ByteData
downLoading(fileObj) {
if (fileObj.fileType) {
this.fileExtentionObj = this.getFileExtension(fileObj.fileType);
this.MimeType = this.fileExtentionObj.MIMETYPE;
}
if (fileObj.dataType == "URL") {
this.url = fileObj.fileURL;
}
else if (fileObj.dataType == "DATAURL") {
this.url = this.fileExtentionObj.BASEURL + fileObj.fileURL;
}
else if (fileObj.dataType == "BYTEDATA") {
this.url = this.fileExtentionObj.BASEURL + fileObj.fileURL;
}
if (this.platform.is('android')) {
this.targetPath = this.file.externalRootDirectory + '/Download/' + fileObj.fileName + '.' + this.fileExtentionObj.EXTENSION; this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE)
.then(status => {
if (status.hasPermission) {
this.downloadFile(fileObj);
}
});
}
else {
this.targetPath = this.file.documentsDirectory + fileObj.fileName + '.' + this.fileExtentionObj.EXTENSION;
this.downloadFile(fileObj);
}
}
//download file at specific target location on ios and android
downloadFile(fileObj) {
var trustHosts = true;
this.fileTransfer.download(this.url, this.targetPath, trustHosts).then(result => {
//show local notification
this.localNotifications.schedule({
title: 'Download Completed..',
text: fileObj.fileName.concat("." + this.fileExtentionObj.EXTENSION),
foreground: true,
icon: 'file://assets/icon/download.png',
});
this.localNotifications.on('click').subscribe(notification => {
this.fileOpener.open(this.targetPath, this.MimeType)
.then(() => console.log('File is opened'))
.catch(e => console.log('Error opening file', e));
});
}).catch(e => {
console.log('Error in downloading File', e);
});
}
I want file to be downloaded on ios device.is there any permission issue for specific to ios or i did something wrong in my code?