I have implemented push notifications using cordova push plugin. My problem is, when the app is not in foreground, i receive push notifications but i don’t know how to access the payload attached to it. I want to extract the message and save in SQLite db locally. I am able to do the same when app is in foreground.
switch( e.event ) {
case 'registered':
//Code to handle registred event
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
if ( e.foreground ) {
//Code to handle foreground notification. e.payload contains the notification message.
} else {
// otherwise we were launched because the user touched a notification in the notification tray.
if ( e.coldstart ) {
//alert('coldstart');
console.log('[+] --COLDSTART NOTIFICATION--');
} else {
console.log('[+] --BACKGROUND NOTIFICATION--');
}
// Should redirect to detail page and append data to databse
redirectToNotificationDetail(e.payload);
}
console.log('[+] PAYLOAD: ' + JSON.stringify(e.payload));
break;
case 'error':
console.log('[-] ERROR -> MSG:' + e.msg);
phonegapService.getToastService().showShortTop('[-] ERROR -> MSG:' + e.msg);
break;
default:
console.log('[-] Unknown, an event was received and we do not know what it is');
break;
}
I’ve run into the same issue. Were you able to resolve this?