Ionic 3: загрузка функциональности не работает в IOS, пока он работает на Android правильно - PullRequest
0 голосов
/ 09 мая 2019

Я использую ионную версию 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?
...