我在React Native中对多个推送通知进行分组/合并时遇到问题,我正在使用RNFirebase(https://rnfirebase.io/),我查找了很多示例,但都失败了,我想对多个推送通知进行分组/合并如WhatsApp,如下面的图片。
这是我的脚本:
async componentDidMount() {
if(Platform.OS === "android") {
const channel = new firebase.notifications.Android.Channel('test-channel', 'Test Channel', firebase.notifications.Android.Importance.Max)
.setDescription('My apps test channel');
// Create the channel
firebase.notifications().android.createChannel(channel);
}
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((Notification) => {
});
this.notificationListener = firebase.notifications().onNotification((Notification) => {
const notification = Notification;
if(Platform.OS === "android") {
notification
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)
.setSound("default")
.android.setGroup('test')
.android.setGroupSummary(true)
.android.setChannelId('test-channel')
.android.setSmallIcon('ic_notification')
.android.setLargeIcon('ic_launcher_round')
.android.setAutoCancel(true)
.android.setColor('#470a49');
firebase.notifications()
.displayNotification(notification);
}else if(Platform.OS === "ios") {
notification
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)
.setSound("default")
.ios.setBadge(notification.ios.badge);
firebase.notifications()
.displayNotification(notification);
}
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((NotificationOpen) => {
const notification = NotificationOpen.notification;
firebase.notifications().removeDeliveredNotification(notification.notificationId);
});
//When notification received when app is closed
this.initialNotification = firebase.notifications().getInitialNotification()
.then((notificationOpen) => {
if (notificationOpen) {
const notification = notificationOpen.notification;
}
});
}
componentWillUnmount() {
this.notificationDisplayedListener();
this.notificationListener();
this.notificationOpenedListener();
}
请任何人帮助我。
谢谢。