I have followed this tutorial and I have the following code:
onDeviceReady I execute:
var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"824841663931","ecb":"app.onNotificationGCM"});
The Handlers:
// 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;
}
}
This code works perfectly if my device is connected to the internet on the first time I open the app.
If my device is not connected the successHandler is being called with "OK" and the onNotificationGCM is never called. Is this normal?
I was expecting that the registration should fail and call the errorHandler or the onNotificationGCM with e.event = 'error' so I would be able to postpone the registration, but this is not happening.
I would appreciate any help, thanks.