我正在向我的应用程序发送多个通知。我想要实现的是,每当用户单击一个通知时,通知托盘中的所有通知都会显示出来。
我试着添加了
notification.android.setAutoCancel(true)它只对一个通知(被点击的那个通知)起作用
我也尝试过:
firebase.notifications().removeAllDeliveredNotifications() 不会有任何效果。
我如何才能做到这一点?
下面是我的完整代码:
componentDidMount() {
firebase.notifications().removeAllDeliveredNotifications()
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
});
this.notificationListener = firebase.notifications().onNotification(async (notification) => {
// Process your notification as required
notification.android.setAutoCancel(true)
firebase.notifications().removeAllDeliveredNotifications()
}
async componentWillMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
});
this.notificationListener = firebase.notifications().onNotification((notification) => {
});
this.notificationDisplayedListener();
this.notificationListener();
}发布于 2019-06-09 13:51:57
尝试将用于删除通知(removeAllDeliveredNotifications())的代码从onNotification侦听器移动到onNotificationOpened侦听器。可能存在竞争条件,因为您正在尝试删除到达时的通知。
还因为您希望在用户点击一个通知时清除通知。
PS。将通知侦听器保留在componentDidMount或componentWillMount中,而不是两者都保留。
https://stackoverflow.com/questions/56157296
复制相似问题