React native 通知-清除android通知托盘中的所有通知

React native 通知-清除android通知托盘中的所有通知,react-native,firebase-cloud-messaging,android-notifications,firebase-notifications,react-native-firebase,React Native,Firebase Cloud Messaging,Android Notifications,Firebase Notifications,React Native Firebase,我正在向我的应用程序发送多个通知。我想要实现的是,每当用户单击一个通知时,通知托盘中的所有通知都会消失 我试着加上 notification.android.setAutoCancel(true) 它只对一个通知(正在单击的通知)起作用 我也试过: firebase.notifications().removeAllDeliveredNotifications() 这没有任何效果 我怎样才能做到这一点 以下是我的完整代码: componentDidMount() { f

我正在向我的应用程序发送多个通知。我想要实现的是,每当用户单击一个通知时,通知托盘中的所有通知都会消失

我试着加上

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

尝试移动用于删除通知的代码 (
removeAllDeliveredNotifications()
)从
onNotification
侦听器到
onNotificationOpened
侦听器。当您试图删除到达时的通知时,可能存在竞争条件

还因为您希望在用户点击一个通知时清除通知


另外,请将通知侦听器保存在
componentDidMount
componentWillMount
中,不要两者都保存。

谢谢!我已经多次尝试删除它(没有两个位置的侦听器),但由于某种原因,通知停止工作:|嘿,我也有同样的问题,你能检查一下吗,@nisantnair