react-native and library version :
"react": "16.13.1",
"react-native": "0.63.1",
"react-native-push-notification": "^4.0.0",
1. I am having a problem of clearing notification when user click on the notification which was sent from FCM console or Remote FCM message. I tried this
PushNotification.cancelLocalNotifications({ id: this.lastId});
PushNotification.cancelLocalNotifications({ id: '' + this.lastId });
But none of these worked.
2. When user taps the notification to open application, i am getting error undefined is not an object.
Below are the errors



What are the proper way to handle notification, FCM and FCM remote message ?
Hi,
this.lastId for a remote notification? The notification id is in the object notification.id. And the notification should also disappear after the click.notif and find what you want. It's probably notif.title.Regards,
Hello, @Dallas62 Thank you for you reply. I tried as you said above, and it is working now. Thank you so much.
notification.id in documentation.notf.data.title for remote message using https://fcm.googleapis.com/fcm/send and notif.title for FCM console message. I flipped the condition and its working now.Now, I am facing another problem, I am not getting notification when app is closed i.e in background from FCM remote message https://fcm.googleapis.com/fcm/send but getting message sent from FCM console.
Thank you
For the problem in background, it has been documented in many issues, even recent one
@vishwa1937 as i explained in the other topic, when the app is open, you get the notification and the data is received through the data{} object, but if the app is closed or minimized! and you click on the notification to open the app but the data doesn't come from the data{} object, you have to access it directly
onNotification(notification) {
if (notification.data) { //// **APP IS OPEN**
notification.data.title
notification.data.message
} else { ///////**APP IS CLOSED!!!**
notification.title
notification.message
}
},
@luigbren , @Dallas62 Thank you so much for your reply. Now, I am able to get notification in foreground, background, and app closed state.
Previously, i used different JSON format of remote message i.e
{
"data": {
"title": "Hello John Doe",
"message": "How are you? How you doing?"
},
"to": "/topics/fcmDemo"
}
I changed this format to :
{
"notification": {
"title": "Hello John Doe",
"body": "How are you? How you doing?"
},
"data": {
"badge": 35,
"payload": {
"message": "This is payload message",
"url": "This is payload url"
}
},
"to": "/topics/fcmDemo"
}
I am able to get FCM notification form FCM console and remote message using https://fcm.googleapis.com/fcm/send.
Most helpful comment
@vishwa1937 as i explained in the other topic, when the app is open, you get the notification and the data is received through the data{} object, but if the app is closed or minimized! and you click on the notification to open the app but the data doesn't come from the data{} object, you have to access it directly