如何在iOS中使用科尔多瓦文件传输的插件下载文件科尔、文件传输、插件、多瓦

2023-09-13 05:18:18 作者:萌一个辣妹子

我用下面的code下载文件:

I have used the following code to download file:

$scope.onDownloadMusic = function( live ) {

    var downloadUrl = offlineUrl + fileName;
    var hostUrl = encodeURI(live.url);

    var fileTransfer = new FileTransfer();
    fileTransfer.download(
        hostUrl,
        downloadUrl,
        function(entry) {
            alert('Your download has completed.');
        },
        function(error) {
            alert(error.source);
        },
        false,
        {
            headers: {
                "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
            }
        }
    );
};

它正常工作在Android上。然而,当我试图在iOS相同code,我总是得到一个错误。

It works fine on Android. However, when I tried the same code on iOS, I always got an error.

我不知道哪里出了问题。任何帮助真的AP preciated。

I didn't know what went wrong. Any help is really appreciated.

推荐答案

我终于找到了解决办法:

I finally found the solution:

简单的一招这需要我相当长的一段时间调查:

Simple trick which takes me quite some time to investigate:

    var downloadUrl = encodeURI(cordova.file.dataDirectory + fileName);
    var hostUrl = encodeURI(live.url);

有趣这里是连接codeURI。

What's interesting here is encodeURI.