I have been looking all over for a guide on how to access Custom data like keys and values in Firebase Cloud Messaging to do a click action for. My goal is to be able to target a specific click action for the notifications I send to my app when the notification is clicked.
How can this be done? I am sending notifications from the Firebase Cloud Messaging console. I saw a post here, but it did not solve my issue.
I am using the following libraries:
import firebase from 'react-native-firebase';
import type { Notification, NotificationOpen } from 'react-native-firebase';
This is what I use to target background opens or closed app opens.
/*
* If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows:
* */
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
const { navigate } = this.props.navigation;
const { title, body } = notificationOpen.notification;
Get custom key values for click action here and use it to navigate.
navigate(key_action??)
});
/*
* If your app is closed, you can check if it was opened by a notification being clicked / tapped / opened as follows:
* */
const notificationOpen = await firebase.notifications().getInitialNotification();
if (notificationOpen) {
const { navigate } = this.props.navigation;
const { title, body } = notificationOpen.notification;
navigate(key_action??)
}