【发布时间】:2013-12-23 02:50:58
【问题描述】:
我最近设法将我的 Phonegap 版本从 2.9 升级到 3.3,并且现在才设法升级我的项目以在 3.3 中工作
我现在收到一个错误,我的应用程序不会进入 deviceready() 状态。在更改为 +3.0 之前,我的应用程序进入 deviceready() 就好了...我已经运行 CLI 'build' 和'update' 命令将我的项目修改为 +3.0 规范,并自行移动了一些东西所以某些错误关于插件的问题将得到解决。
我还应该提到,我最近才添加了这部分,它似乎解决了一个 NPObject 错误(在 phonegap 生成的 helloworld 应用程序中看到它,我想我应该添加它):
<script src="js/index.js">app.initialize()</script>
这里是应该调用 deviceready 的相关 html 代码块:
在 index.html 内:
<script src="js/jquery.js"></script>
<script src="js/jquery.mobile-1.2.0.js"></script>
<script src="cordova/lib/cordova.js"></script>
<script src="js/index.js">app.initialize()</script>
<script src="js/mustache.js"></script>
<script>
.
.
.
function init() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
//db = window.openDatabase("Notes","1.0","Saved Notes", 200000);
//db.transaction(getDBNotes, onDBError, onDBSuccess);
console.log("WITHIN onDeviceReady()");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, onFSError);
}
这是我的 index.js 文件,以防万一这很重要:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
console.log("within index.js- app.onDeviceReady()");
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
当我在设备上的 eclipse 中运行我的应用程序时,我收到此错误:
"deviceready has not fired after 5 second.", source: file://android_asset/www/cordova.lib/cordova.js
我一直在绞尽脑汁试图启动并运行这个项目,以便继续开发,但我似乎无法解决这个问题。
感谢您的帮助!
【问题讨论】:
-
将此代码放在列表顶部,因为cordova.js文件应该声明在所有js文件的顶部。跨度>
-
试过了,没用。这无关紧要,因为在 cordova.js 之前运行的唯一脚本是 jquery 和 jquery 移动脚本库,它们与 deviceready 问题无关。
-
我似乎已经通过将 cordova_plugins.js 文件移回 android_assets/www/ 的根目录并简单地在我的 index.html 中添加对插件的引用来解决这个问题
-
哦,我还将对我的 cordova.js 文件的引用从 cordova/lib/ 更改为在根目录中找到的 cordova.js 文件......我想我可能是在引用 2.9 cordova.js文件而不是新建的 3.3 js 文件。
-
是的,您的上述问题没有找到 cordova.js 文件,因此无法进入 deviceready()。所以下次要小心cordova.js版本和参考