我一直在尝试按 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 对它们进行分组吗?
最佳答案
这个怎么样:-
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)
}
}
关于react-native - 按 ID 分组通知并像 Whatsapp 一样显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56518235/