Error code 3 when downloading files with fileTransfer on iOS

0

In an application I'm working on the client needs a button to download a PDF that will be generated on their server.

The PDF is being generated without problems, the file is saved in a folder of the server and through a webservice SOAP I pass the URL of the file to the APP.

So far, everything working without problems.

On Android the file is saved in the downloads folder and there it stays, already tested and is working, now when I try on iOS (save in user documents, so it can access the PDF with other programs) the script returns me error 3 (FileTransferError.CONNECTION_ERR).

According to the message seems to be a connection error, but this does not happen with Android, only on iOS (I'm using the same Xcode simulator).

Some of my code to understand how it works, this section defines the "root" path to save the files, is getting the right paths:

document.addEventListener('deviceready', function () {
    if(device.platform=="iOS"){
        $(".paraIOS").show(); //Mostra comandos exclusivos do iOS
        diretorioDownloads=cordova.file.documentsDirectory;
    }
    else if(device.platform=="Android") diretorioDownloads=cordova.file.externalRootDirectory+"Download/";
}, false);

This is the function that downloads the file:

function baixarArquivo(arquivo,nome,tamanho){
    window.requestFileSystem(LocalFileSystem.PERSISTENT, tamanho, function (fs) {
        fs.root.getFile(nome, { create: true, exclusive: false }, function (fileEntry) {
            var fileTransfer = new FileTransfer();
            var fileURL = diretorioDownloads+nome;
            console.log("Baixando arquivo "+arquivo+" para "+fileURL);
            fileTransfer.download(
                arquivo,
                fileURL,
                function (entry) {
                    alerta("Arquivo baixado com sucesso");
                    logar("Download","Processo finalizado: " + entry.toURL());
                },
                function (error) {
                    console.log("Erros");
                    console.log(error);
                },
                null,
                {
                    headers: {Connection: "close"}
                }
            );

        }, function(e){
            alerta("Erro ao criar o arquivo",true);
            logar("Download",["Erro ao criar o arquivo",e]);
        });

    }, function(e){
        alerta("Erro ao carregar sistema de arquivos",true);
        logar("Download",["Erro ao carregar sistema de arquivos",e]);
    });
}

Explaining the variables:

file: The URL of the file on the server

name: the name to save the file

size: the size in bytes of the file

I checked it and it passes exactly what it should. (Note: alert is supposed to be anyway, not alert )

In summary: The function works on Android, but on iOS (simulator) it returns the error code 3 when downloading the file in the fileTransfer.download function and I do not have one iOS device here to test.

My question is:

Is it possible that this only happens on iOS? or do they have some function failure that I'm not finding?

What I've already tried:

  • Check access origin="*"
  • Use headers: {Connection: "close"} as download option.
  • Change the destination folder of the file in iOS.
asked by anonymous 25.06.2018 / 22:22

0 answers