2017-08-10 36 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有關。

相關問題