通过ID对通知进行分组并显示类似Whatsapp的内容

时间:2019-06-09 20:42:19

标签: react-native firebase-cloud-messaging android-notifications firebase-notifications react-native-firebase

我一直试图通过 id 将通知分组,例如将它们显示为WhatsApp,而每行没有一个通知。

setGrouponNotification中添加onNotificationDisplayed似乎无效,请参见以下示例:

1

componentDidMount() {
this.notificationListener = firebase.notifications().onNotification(async (notification) => {
  // Process your notification as required
  notification.android.setAutoCancel(true)

  notification.android.setGroup(notification.data.channelId)
  notification.android.setGroupSummary(true)
} 
}

2

componentDidMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
   notification.android.setGroup(notification.data.channelId)
  notification.android.setGroupSummary(true)
});
}

有人知道如何按ID对它们进行分组吗?

1 个答案:

答案 0 :(得分:0)

这如何:-

componentDidMount() {
    var zero = firebase.notifications().onNotification((notification) => {
        this.setState({
            channelId=notification.data.channelId,
            Title=notification.data.Title,
            Body=notification.data.Body
//basically get all the data from the notification the you receieve from notification into states.
        });
    });
    if(this.state.channelId === "WhatsApp"){
        this.notificationDisplayedListener = 
            notification.android.setAutoCancel(true)
            notification.android.setTitle(this.state.Title)
            notification.android.setBody(this.state.Body)
            notification.android.setGroup(this.state.channelId)
            notification.android.setGroupSummary(true)
    }
}