【问题标题】:Phonegap 3.3.0 iOS FileSystem plugin not firing complete, progress or errorPhonegap 3.3.0 iOS FileSystem 插件未触发完成、进度或错误
【发布时间】:2014-02-14 19:05:17
【问题描述】:

我正在尝试将 iOS 上的 FileTransfer 插件与 Phonegap 3.3.0 一起使用。过去它一直在我的应用程序中运行,但自从我更新了所有库 JQuery (1.11.0)、JQuery Mobile(1.4.1) 后,我没有收到与文件传输相关的任何回调。

我知道文件正在下载,因为我可以看到它们出现在 iOS 模拟器临时文件等文件系统中。此外,随着文件显示完成,它们似乎已完成下载。

我的代码:

function download(url, dest, cb) {

    var fileTransfer = new FileTransfer();
    console.log("remote:"+url+" local:"+dest);

    fileTransfer.onprogress = progress;
    fileTransfer.download(url, dest, downloadSuccess, fail);
}
function progress() {
    console.log("progress:"+arguments);
}
function fail() {
    console.log("fail:"+arguments);
}
function downloadSuccess() {
    console.log("download complete: " + arguments);
}

有什么想法我可能做错了吗?

【问题讨论】:

    标签: javascript jquery ios cordova phonegap-plugins


    【解决方案1】:

    Phonegap 3.3.0 的文件系统有一种新方法。如果您一直使用完整路径进行输入,则需要将其替换为 toURL()。

    同样在你的 config.xml 文件中你必须添加

    <preference name="iosPersistentFileLocation" value="Compatibility" />
    

    最好的办法是浏览此链接https://github.com/apache/cordova-plugin-file/blob/dev/doc/index.md

    进行这些更改对我有用。希望它也对你有用。

    【讨论】:

      【解决方案2】:

      我认为您的回调已触发,但您有语法错误,因为您尝试使用 arguments 参数但未定义它。

      此外,由于回调采用对象,使用 console.log 中的参数,它只会显示“对象”。您应该对其进行字符串化或使用对象的属性。

      例如:

      function download(url, dest, cb) {
      
          var fileTransfer = new FileTransfer();
          console.log("remote:"+url+" local:"+dest);
      
          fileTransfer.onprogress = progress;
          fileTransfer.download(url, dest, downloadSuccess, fail);
      }
      function progress(arguments) {
          console.log("progress:"+Math.floor(100*arguments.loaded/arguments.total)+"%");
      }
      function fail(arguments) {
          console.log("fail error code:"+arguments.code);
      }
      function downloadSuccess(arguments) {
          console.log("download complete: " + arguments.bytesSent + " bytes sent");
      }
      

      【讨论】:

      • 在每个 JavaScript 函数中,您都可以访问 arguments 数组,该数组包含(您猜到了)被调用的函数接收到的 参数。所以这不是问题。 Apache 在他们的错误跟踪系统 (issues.apache.org/jira/browse/CB-9936) 中注册了同样的错误。所以这确实是 Phonegap/Cordova 文件传输插件中的一个错误。我只是不知道是否已经有解决方案,或者我们是否只能使用问题中解释的解决方法。
      猜你喜欢
      • 2014-02-05
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多