【问题标题】:Phonegap fileTransfer.Download is not working on ios phonegap 3.0Phonegap fileTransfer.Download 不适用于 ios phonegap 3.0
【发布时间】:2014-06-22 16:02:48
【问题描述】:

我正在使用 JQM 开发一个应用程序,然后使用 build.phonegap.com,我正在构建该应用程序。

我有一个功能可以从服务器下载音频文件,然后在应用程序中播放。

它在 android 中完美运行。

我尝试了所有可能的方法。

有人可以帮忙吗?

这是我完整的文件处理代码

fileSystem.root.getDirectory("auidofiles", {
        create : true,
        exclusive : false
    }, function(dirEntry) {     


        dirEntry.getFile(mp3_file, {
            create : false,
            exclusive : false
        }, function(fileEntry) {    

            alert("File Already downloaded");               

            if (device.platform == "Android") { 
                FILEPATH = fileEntry.fullPath;
                //FILEPATH = fileEntry.toURI();
                playAudio();                    
            } else {
                var filePathLocal1 = getPhoneGapPath() + "auidofiles/" +  mp3_file; 
                //var filePathLocal = fileSystem.root.toURL() + "auidofiles/" +  mp3_file;  
                //alert("Ios File Path:" + filePathLocal);
                //FILEPATH = filePathLocal;
                //FILEPATH = fileEntry.fullPath;
                //FILEPATH = fileEntry.toURI();
                playAudio();
            }


        }, function(fileFail) {

            alert("File Not found");

            var ft = new FileTransfer();

            ft.onprogress = function(progressEvent) {

                if (progressEvent.lengthComputable) {
                    var perc = Math.floor(progressEvent.loaded
                            / progressEvent.total * 100);
                    $('#downloadStatus').html(perc + "% loaded...");
                } else {

                    if ($('#downloadStatus').html() == "") {
                        $('#downloadStatus').html("Loading");
                    } else {
                        $('#downloadStatus').html(
                                $('#downloadStatus').html() + ".");
                    }
                }
            }; //ft.Progress

            var filePathLocal = fileSystem.root.toURL() + "auidofiles/" +  mp3_file;    
            ft.download(audioStreamUrl, filePathLocal, function(entry) {    

                //alert("File = " + entry.toURI()); 
                if (device.platform == "Android") {
                    FILEPATH = entry.fullPath;
                    //FILEPATH = entry.toURI();
                    playAudio();
                } else {
                    var filePathLocal1 = getPhoneGapPath() + "auidofiles/" +  mp3_file; 
                    //alert("Ios File Path:" + filePathLocal);
                    FILEPATH = filePathLocal;
                    //FILEPATH = entry.fullPath;
                    //FILEPATH = entry.toURI();
                    playAudio();
                }

            }, function(error) {

                $('#downloadStatus').html(
                        "download error source " + error.source);
                $('#downloadStatus').html(
                        "download error target " + error.target);
                $('#downloadStatus').html("upload error code" + error.code);

            }); //ft.Download           
        }); //getFile End

    }, function(dirfail) {
        alert("dirfail");   
        alert(JSON.stringify(dirfail))
        $('#downloadStatus').html(JSON.stringify(dirfail));
    })

function getPhoneGapPath() {

var path = window.location.pathname;
path = path.substr( 0, path.length - 10 );
return 'file://' + path;

};

【问题讨论】:

标签: android ios jquery-mobile cordova


【解决方案1】:

有一个新要求是使用 .toURL() 代替 .fullPath

这解决了大多数此类问题 - 但是我在使用旧版本的 iOS (5.x) 时遇到了类似的问题,其中 filetransfer.download 永远不会触发成功/失败/进度事件,即使它确实下载了文件。然后,当我尝试重新启动应用程序时,应用程序崩溃...

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,并通过在使用 Phonegap/Cordova v3.3 时将 Cordova 插件 FileTransfer 从 v0.4.2 降级到 v0.3.3 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2013-08-31
      • 2013-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-11
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      相关资源
      最近更新 更多