2017-08-10 76 views
10

我用科尔多瓦文件的插件 - cordova file plugin读取文件中使用科尔多瓦文件插件

实际上,我从阅读文本文件的文件。下面是我的代码

document.addEventListener("deviceready", function() { 
    window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "sameple.txt", gotFile, fail); 
}, true); 

function gotFile(file) {   
    file.file(function (file) {     
     var reader = new FileReader(); 
     reader.onloadend = function (evt) {   
      console.log(this.result); 
     } 
     reader.readAsText(file);     
    }, fail());    
} 

function fail(e) { 
    console.info("FileSystem Error : " + e); 
} 

所以每当我运行这段代码,我提示以下错误:

deviceready has not fired after 5 seconds. 
Channel not fired: onPluginsReady 
Channel not fired: onCordovaReady 

Could not get Cordova FileSystem: Error: deviceready has not fired after 5 seconds. 
    "Could not get Cordova FileSystem:" 
    { 
     [functions]: , 
     __proto__: { }, 
     description: "deviceready has not fired after 5 seconds.", 
     message: "deviceready has not fired after 5 seconds.", 
     name: "Error" 
    } 

{"data":"data"} 

deviceready error后来我能够得到确切的数据..请问该如何解决这个错误?我是否必须等待设备准备好执行才能完成?

+1

你在源文件中包含cordova.js文件吗? – Gandhi

+0

对此有何更新? – Gandhi

回答

5

这可能有多种原因,详见here

你应该尝试冷杉@bayanAbuawad suggestion的作品时代最:

  1. 添加与科尔多瓦平台添加IOS的android

  2. 与科尔多瓦平台删除它们删除IOS Android上的平台

  3. 再次添加它们。

这是超级怪异的,但它与平台文件夹内的错误android.json和ios.json有关。