本文介绍了如何在iOS中使用科尔多瓦文件传输的插件下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的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.
这篇关于如何在iOS中使用科尔多瓦文件传输的插件下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!