gpt4 book ai didi

javascript - 使用 Cordova 文件插件读取文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:09:39 24 4
gpt4 key购买 nike

我正在使用 cordova 文件插件 - 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 错误 之后,我能够获得准确的数据。我该如何解决这个错误?我是否必须等待设备就绪执行完成?

最佳答案

发生这种情况的原因有很多,请参阅 here更多详情。

你应该先试试@bayanAbuawad suggestion大多数时候都有效:

  1. 使用cordova platform add ios android 添加平台

  2. 使用 cordova platform remove ios android 删除它们

  3. 再次添加它们。

super 奇怪,但它与平台文件夹中的错误 android.json 和 ios.json 有关。

关于javascript - 使用 Cordova 文件插件读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45608080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com