2017-08-10 19 views
10

Tôi đang sử dụng plugin tệp cordova - cordova file pluginĐọc tệp bằng Cordova File Plugin

Tôi đang đọc tệp từ tệp văn bản. Dưới đây là mã của tôi

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); 
} 

Vì vậy, bất cứ khi nào tôi chạy mã này, tôi nhận được các lỗi dưới đây

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"} 

Sau deviceready error sau tôi có thể nhận được các dữ liệu chính xác .. Làm thế nào để tôi giải quyết lỗi này? tôi có phải đợi thiết bị sẵn sàng thực hiện để hoàn thành không?

+1

Bạn đã bao gồm tệp cordova.js trong tệp nguồn của mình chưa? – Gandhi

+0

bất kỳ cập nhật nào về điều này? – Gandhi

Trả lời

5

Điều này có thể xảy ra vì một số lý do, xem chi tiết hơn here.

Bạn nên cố gắng linh sam @bayanAbuawad suggestion mà làm việc hầu hết các lần:

  1. Thêm nền tảng với nền tảng cordova thêm ios android

  2. Hủy bỏ chúng với nền tảng cordova loại bỏ ios android

  3. Thêm lại họ.

Nó là siêu lạ, nhưng nó liên quan đến một android.json bị lỗi và ios.json bên trong thư mục nền tảng.

Các vấn đề liên quan