Push notification after tapped is clicked not working
Hello All, I’m working with push notifications in one of my Ionic 2 Application.
Just stucked when the app is not running in the foreground that means when the app is closed and push notification triggers, its showing up properly but when its tapped the application starts up but the code after push is not working :s
pushObject.on(‘notification’).subscribe((data: any) => {
console.log(‘Data returned’, data); //if user using app and push notification comes if (data.additionalData.foreground) { console.log(“app is running”); } else { //if user NOT using app and push notification comes //TODO: Your logic on click of push notification directly console.log(‘Push notification clicked’, data); } });
I’m unable to see this ‘Push notification clicked’ log, how to check my after push code is working properly?
Any help will be highly appreciated!
Thanks.
Hello Try sending the information in this way
My recommended format for your push payload when using this plugin (while it differs from Google's docs) works 100% of the time:
{ "data" : { "title": "Test Notification", "body": "This offer expires at 11:30 or whatever", "notId": 10, "surveyID": "ewtawgreg-gragrag-rgarhthgbad" } }
Here is the explanation Notification vs Data Payloads
Ok I got it but I'm using FCM, and sending notification from firebase console. What is the notId and surveyID?
Can you please help me? This is not working on Android -_-
@ShafiqEssani Hello, Have you found a solution? Thank you
@ShafiqEssani excuse me, the noteId and surveyId are dummy data taken from the documentation.
After in my app.component.ts I capture the events like this.
pushObject.on('notification').subscribe((data: any) => {
if(data.additionalData.foreground) {
this.onConfirmNotification(data.additionalData.news)
} else {
this.showNewsModal(data.additionalData.news);
}
});
Remember to send the push in format Data Payloads
Goodbye.
@StefanoMartella I'm still looking for it :/ If anyone can help me :(