我一直在寻找有关如何访问自定义数据(如Firebase Cloud Messaging中的键和值)以进行点击操作的指南。我的目标是能够为点击通知后发送给我的应用的通知指定特定的点击操作。
这怎么办?我正在从Firebase Cloud Messaging控制台发送通知。 I saw a post here, but it did not solve my issue.
我正在使用以下库:
import firebase from 'react-native-firebase';
import type { Notification, NotificationOpen } from 'react-native-firebase';
这是我用来定位后台打开或关闭的应用程序打开的内容。
/*
* 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??)
}