PhoneGap 事件未在 iPhone 上触发
我已经开始使用 PhoneGap 和运行 iOS 5 的 iPhone 进行开发。使用以下代码,当应用程序启动时,deviceready 和 online 事件似乎会触发,但其他事件(特别是恢复/暂停事件)不会触发。我尝试使用菜单按钮关闭应用程序,然后重新打开它,但似乎没有任何内容触发恢复事件。
如果有人能阐明这一点,我们将不胜感激。
提前致谢!
window.addEventListener('load', function () {
document.addEventListener('deviceready', onDeviceReady, false);
}, false);
function onDeviceReady() {
document.addEventListener('resume', onResume, false);
document.addEventListener('pause', onPause, false);
document.addEventListener('online', onOnline, false);
document.addEventListener('offline', onOffline, false);
}
function onResume() {
alert('resume');
}
function onPause() {
alert('pause');
}
function onOnline() {
alert('online');
}
function onOffline() {
alert('offline');
}
I've started developing for iPhone using PhoneGap and an iPhone running iOS 5. With the following code, the deviceready and online events appear to fire when the application starts but none of the others, in particular, the resume / pause events appear to. I've tried using the menu button to close the app and then re-open it but nothing appears to fire the resume event.
If anyone could shed any light on this it would be much appreciated.
Thanks in advance!
window.addEventListener('load', function () {
document.addEventListener('deviceready', onDeviceReady, false);
}, false);
function onDeviceReady() {
document.addEventListener('resume', onResume, false);
document.addEventListener('pause', onPause, false);
document.addEventListener('online', onOnline, false);
document.addEventListener('offline', onOffline, false);
}
function onResume() {
alert('resume');
}
function onPause() {
alert('pause');
}
function onOnline() {
alert('online');
}
function onOffline() {
alert('offline');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,这是一个 ID10-T 错误:我的 PhoneGap 应用程序正在重定向到我拥有的 URL一个地方发生了变化,但另一处没有变化。结果是,看起来我正在运行我的开发代码,但实际上我是在运行没有 onResume 和 onPause 事件的代码的远程服务器上运行!
顺便说一句,这些事件的文档可以在 http://docs.phonegap 找到.com/en/1.4.1/phonegap_events_events.md.html
For me this was an ID10-T error: my PhoneGap app was redirecting to a URL which I had changed in one place but not in the other. The result was it looked like I was running my development code but I was actually running against a remote server running code without onResume and onPause events!
BTW, documentation for these events can be found at http://docs.phonegap.com/en/1.4.1/phonegap_events_events.md.html