我已按照本教程进行操作,并且有以下代码:
onDeviceReady 我执行:
var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"824841663931","ecb":"app.onNotificationGCM"});
处理程序:
// result contains any message sent from the plugin call
successHandler: function(result) {
alert('Callback Success! Result = '+result)
},
errorHandler:function(error) {
alert(error);
},
onNotificationGCM: function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
alert('registration id = '+e.regid);
localStorage.regid = e.regid
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = '+e.message+' msgcnt = '+e.msgcnt);
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
如果我的设备在我第一次打开应用程序时连接到互联网,则此代码可以完美运行。
如果我的设备未连接,则使用“OK”调用successHandler,并且永远不会调用onNotificationGCM。这是正常的吗?
我原以为注册会失败并使用 e.event = 'error' 调用 errorHandler 或 onNotificationGCM,这样我就可以推迟注册,但这并没有发生。
我会很感激任何帮助,谢谢。