如何在React Native中点击时关闭Firebase通知

时间:2019-06-20 13:15:57

标签: react-native

如何取消反应式水龙头上的通知。

我在react native及其工作中集成了通知,但是当我点击通知时,我想关闭通知。

我正在收到以下函数的回叫。

firebase.notifications().onNotificationOpened((notificationOpen)  => {
         const { title, body } = notificationOpen.notification;

         console.log("Notification Received - " + body)    
}

1 个答案:

答案 0 :(得分:0)

添加此行

notification.android.setAutoCancel(true);
到您的代码

this.notificationListener = firebase.notifications().onNotification(notification => {
            console.log("OnNotification", notification)
            notification.setTitle("MyApp")
            notification.android.setPriority(firebase.notifications.Android.Priority.High)
            notification.android.setAutoCancel(true) //add this line
            notification.android.setChannelId("test-channel")
            firebase.notifications().displayNotification(notification);
    })