我一直试图通过 id 将通知分组,例如将它们显示为WhatsApp,而每行没有一个通知。
在setGroup
或onNotification
中添加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对它们进行分组吗?
答案 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)
}
}