0

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??)
  }
AL.
  • 36,815
  • 10
  • 142
  • 281
vemund
  • 1,667
  • 4
  • 29
  • 43
  • 1
    which library are you using to handle push notifications? – Haider Ali Oct 18 '18 at 17:06
  • @HaiderAli I am using the Firebase Cloud Messaging console to send notifications, and I am using react-native-firebase to handle the push notifications. – vemund Oct 18 '18 at 17:08

0 Answers0