I am trying to build react-native app which has push notification implemented using react-native-push-notification. Now, when the app is in 'foreground', I am able to handle the notification.title and notification.message and displaying in an alert in the app (Through, PushNotification.configure's onNotification). When the app in in 'background', I am able to receive notification and when I click it, the app gets opened up or comes to the foreground. Here, I want to fetch the same notification.title and notification.message to display, but don't see these fields in notification JSON (notification.data is also empty). Following is the code from PushNotification.configure's onNotification:
onNotification: function (notification) {
console.log('NOTIFICATION:', JSON.stringify(notification));
if (notification.foreground) {
if(notification.userInteraction) {
Alert.alert("Title:" + notification.title + " Message:" + notification.message);
} else {
PushNotification.localNotification({
id: notification.id,
autoCancel: true,
title: notification.title,
message: notification.message,
vibrate: true,
vibration: 300,
playSound: true,
soundName: 'default',
});
PushNotification.cancelLocalNotifications({id: notification.id});
}
} else {
console.log("notification.data:", JSON.stringify(notification.data));
if(notification.userInteraction) {
console.log("Showing modal with notification details...");
}
}
},
Thank you for your time to look into this.