RN FireBase 推送通知,应用关闭时无法访问通知标题和 body (getInitialNotification)

RN FireBase push notification, cant access notification title & body when app is closed (getInitialNotification)

下面的代码工作正常,除了当我关闭 运行 并单击下一个传入通知时没有标题和 body。

我在下面分享代码,

async createNotificationListeners() {
    /*
    * Triggered when a particular notification has been received in foreground
    * */
    this.notificationListener = firebase.notifications().onNotification((notification) => {
      const { title, body } = notification;
      console.log('onNotification:');

        const localNotification = new firebase.notifications.Notification({
          sound: 'sampleaudio',
          show_in_foreground: true,
        })
    ...

    this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
      const { title, body } = notificationOpen.notification;
      console.log('onNotificationOpened:');
      Alert.alert(title, body)
    });


    const notificationOpen = await firebase.notifications().getInitialNotification();

    if (notificationOpen) {
      debugger
      const { title, body } = notificationOpen.notification; // title and body undefined
      const { data } = notificationOpen.notification;// and data has only google.delivered_priority ..
      console.log('getInitialNotification:');
      Alert.alert(title, body)
    }

  }

如何通过点击收到的通知打开应用获取通知内容,

我的应用包json喜欢;

"dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-firebase": "^5.5.6"
  },

当应用程序关闭时,您的侦听器将不会在 React Native 中工作,而不是仅在应用程序处于 前台和后台 时才有效。因此,对于应用程序关闭时的状态,您必须在您的 React Native 应用程序中添加一个后台任务。

Now you have to use HeadlessJS funtionality which is available in react native.

你可以在这里参考 Firebase 官方文档:- https://rnfirebase.io/docs/v5.x.x/messaging/receiving-messages#4)-(Optional)(Android-only)-Listen-for-FCM-messages-in-the-background

希望这对您有所帮助....谢谢 :)

@abhikumar22 有新的 Url 回答:

https://v5.rnfirebase.io/docs/v5.x.x/messaging/receiving-messages#4)-(可选)(Android-only)-Listen-for-FCM-messages-in-the-background