[英]Phonegap deviceReady not firing
Please excuse me if this is something simple I am overlooking. 如果这是我忽略的简单事情,请原谅。 I am making my first foray into app development using the PhoneGap/Cordova platform, I appear to be stuck at the first hurdle. 我正在使用PhoneGap / Cordova平台进行应用开发,这似乎是我遇到的第一个障碍。 My deviceReady listener doesn't appear to be firing. 我的deviceReady侦听器似乎未触发。
My code looks like so: 我的代码如下所示:
alert('0');
document.addEventListener("deviceready", function(){
alert('1');
db = window.openDatabase("testproject", "1.0", "PhoneGap Test", 200000);
alert('2');
if (dbCreated){
alert('3');
db.transaction(getData, transaction_error);
} else {
alert('4');
db.transaction(populateDB, transaction_error, populateDB_success);
}
}, false);
the initial alert('0')
(put in to make sure I am actually connecting to the file) is firing but nothing else is happening. 初始alert('0')
(输入以确保我实际上已连接到文件)正在触发,但没有其他反应。
In another post on here. 在这里的另一篇文章中。 Someone else with a similar problem was promted to try document.addEventListener("deviceready", deviceReadyFunction, true)
which solved the issue for them, but not for me. 有人促使其他人遇到类似的问题,尝试使用document.addEventListener("deviceready", deviceReadyFunction, true)
,它为他们解决了这个问题,但对我来说却没有。
As a side question, how do you go about debugging javascript and inspecting the clientside databases in PhoneGap development? 附带的问题是,如何在PhoneGap开发中调试JavaScript和检查客户端数据库? When developing for the web I obviously have firebug and many other tools, however with PhoneGap dev relying heavily on deviceready which is not triggered by a browser are there any tools I should be aware of? 在开发Web时,我显然拥有Firebug和许多其他工具,但是PhoneGap开发人员严重依赖设备就绪,而这并非由浏览器触发,我是否应该注意任何工具? (I am writing my code in Coda but compiling from Xcode). (我用Coda编写代码,但从Xcode编译)。
I have together the code and it works fine, i have tested using Cordova 1.7 and Android 2.2 我在一起的代码,它工作正常,我已经使用Cordova 1.7和Android 2.2进行了测试
var dbCreated = false;
document.addEventListener("deviceready",
function() {
alert('1');
db = window.openDatabase("testproject", "1.0", "PhoneGap Test",
200000);
alert('2');
if (dbCreated) {
alert('3');
db.transaction(getData, transaction_error);
} else {
alert('4');
db.transaction(populateDB, transaction_error,
populateDB_success);
}
}, false);
function getData() {
}
function transaction_error() {
}
function populateDB(tx) {
}
function populateDB_success() {
}
Full source code - https://gist.github.com/3064728 完整的源代码-https://gist.github.com/3064728
For debugging, use weinre it is a really good tool to debug javascript applications on mobile devices. 对于调试,请使用weinre,它是在移动设备上调试javascript应用程序的非常好的工具。
http://people.apache.org/~pmuellr/weinre/docs/latest/ http://people.apache.org/~pmuellr/weinre/docs/latest/
PhoneGap is also using it via - debug.phonegap.com PhoneGap也通过-debug.phonegap.com使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.