我正在使用 phonegap(cordova) 3.0.0 编写应用程序,并且事件“在线”和“离线”不起作用。当我尝试事件“恢复”时,该事件正常。我正在使用 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);
}
};
感谢您的建议