【问题标题】:filePluginIsReady event is never fired in chrome when using cordova-plugin-file使用 cordova-plugin-file 时,chrome 中永远不会触发 filePluginIsReady 事件
【发布时间】:2015-12-17 07:15:58
【问题描述】:

我现在正在开发一个科尔多瓦应用程序,其平台是浏览器(Chrome)。

使用 cordova-plugin-file 读取文件失败。

根据cordova-plugin-file : Chrome quirks的文档,它说:

Chrome 文件系统在设备就绪事件后未立即就绪。作为一种解决方法,您可以订阅filePluginIsReady 事件....您可以使用window.isFilePluginReadyRaised 函数来检查是否已经引发了事件。

我的代码是这样写的:

document.addEventListener('deviceready', dataRead, false);
function dataRead() {
  window.addEventListener('filePluginIsReady', readyToRead, false);
  console.log(window.isFilePluginReadyRaised());
}

function readyToRead(){
  window.initPersistentFileSystem(10*1024*1024, function() {
    var fs = cordova.file.applicationDirectory;
    console.log(fs);
    window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "www/1111.csv", gotFile, fail);
  },function (e) {
    console.log(e);
  });
}

function fail(e) {
  console.log("FileSystem Error");
  console.dir(e);
}

function gotFile(fileEntry) {
  fileEntry.file(function(file) {
    var reader = new FileReader();

    reader.onloadend = function(e) {
      console.log("Text is: "+this.result);
    }
    reader.readAsText(file);
  });
}

读取文件失败,控制台消息如下:

为文件添加代理 ------------------cordova.js:942

授予永久 fs 配额 ---------Preparing.js:170

false --------------------------------------app.js:4(值为window.isFilePluginReadyRaised())

似乎filePluginIsReady 事件没有触发!为什么?

此外,如果我直接在deviceready 事件下编写代码。它也会失败并显示以下错误消息:

代码:5

消息:“提供给 API 的 URI 格式不正确,或者生成的数据 URL 已超出数据 URL 的 URL 长度限制。”

名称:“编码错误”

谁能指出原因或给我一个正确的例子?

感谢任何帮助。

【问题讨论】:

  • 我也有同样的问题。你找到解决办法了吗?谢谢。
  • 关闭cordova运行浏览器打开的Chrome实例重启后终于可以使用了

标签: cordova google-chrome cordova-plugins html5-filesystem cordova-plugin-file


【解决方案1】:

可能发生这种情况的一件事是,您附加到 filePluginIsReady 的时间可能已经触发了该事件。尝试订阅 appStart.js 或应用中的第一个文件中的事件。它对我有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 2018-02-20
    • 2011-11-19
    • 1970-01-01
    • 2019-02-20
    相关资源
    最近更新 更多