Trying to handled push Notification using PushPlugin. Following is my code.
onNotificationGCM: function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
//alert('registration id = '+e.regid);
sDeviceId = e.regid;
//alert(sDeviceId);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = '+e.message);
alert('message = '+e.message+' msgcnt = '+e.msgcnt);
if ( e.foreground )
{
alert("Notification Received");
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if ( e.coldstart )
{
alert("coldstart");
}
else
{
alert("other than coldstart");
}
}
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
So Everything is working.
when application is in foreground I am getting the alert.
when click the notification when message is received application opens and I am getting the alert.(coldstart)
when application is in the background and then clicking on notification the application comes in foreground and I am getting the alert.
But when I keep the application to background and when push notification arrives without clicking on notification when I bring the application to the front i get no alert.So how to handle this type of situation?
See Question&Answers more detail:os