【问题标题】:Group notifications by id and display like Whatsapp按 id 分组通知并像 Whatsapp 一样显示
【发布时间】:2019-06-09 20:42:19
【问题描述】:

我一直在尝试按 id 对通知进行分组,以将它们显示为 WhatsApp,例如,每行没有一个通知。

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

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 对它们进行分组吗?

【问题讨论】:

  • 您确定每个通知的 notification.data.channelId 都保持不变吗?
  • 是的,每个通知都一样

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


【解决方案1】:

这个怎么样:-

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)
    }
}

【讨论】:

  • 嘿,感谢您的回复,但您发送的代码似乎与我描述的问题无关
猜你喜欢
  • 1970-01-01
  • 2023-01-02
  • 2016-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多