我正在使用PhoneGap(Cordova)3.0.0编写应用程序,但是“online”和“offline”事件无法正常工作。当我尝试使用“resume”事件时,它可以正常工作。我正在使用XCode 4.5和IOS。
这是我PhoneGap项目的主要JavaScript文件:
var app = {
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);
document.addEventListener('online', this.onDeviceOnline, false);
document.addEventListener('resume', this.onDeviceResume, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
onDeviceOnline: function() {
app.receivedEvent('deviceonline');
},
onDeviceResume: function() {
app.receivedEvent('deviceresume');
},
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);
}
};
感谢您的建议。