javascript - 如何在 react native 中设置对点击通知的 react ?

标签 javascript android firebase react-native push-notification

我希望应用程序在单击通知后打开正确的 View 。

我试图设置 notificationOnOpenListener,并在不同的地方初始化它。

我已经有一个显示通知的工作函数:

function showNotification(notification){
   PushNotification.localNotification(notification)
}

这就是我想要做的:

this.notificationOnOpenListener = 
    firebase.notifications().onNotificationOpened((notificationOpen) => {

    testNotification(5)
});

其中 testNotification 只是一个调用 Alert.alert 和 ToastAndroid.show 的函数,所以我可以看到它正在工作。

react native -cli:2.0.1 react native :0.55.4 节点-v v8.9.3

我原以为当我点击通知时会出现警告,但什么也没发生。

最佳答案

解决方法:

const notificationOpen = await firebase.notifications().getInitialNotification()
            if (notificationOpen) {
                console.log('Opened notification', notificationOpen)
                this._handleOpenNotification(notificationOpen.notification)
            }

            this.notificationOpenListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
                console.log('Opened notification', notificationOpen)
                this._handleOpenNotification(notificationOpen.notification)
            })

关于javascript - 如何在 react native 中设置对点击通知的 react ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54039124/

相关文章:

javascript - 获取可缩放旭日中可见的根节点

Android onfling 概率

ios - Firebase 通知在 iOS 10 上触发了错误的委托(delegate)

javascript - Vuejs : Can't pass object to web component using v-bind

javascript - 使用 AngularJS 过滤和搜索

android - Google Play 游戏服务——解锁的成就是否会通过 g+ 自动分享?

java - 房间 : performance of insert(Object) vs insert(List<Object>)

android - Firebase 云消息传递 : push notification and navigate to specific page of application

angular - 将 ID 保存到 Firestore 文档

javascript - 使用 Javascript 变量作为 WP_Query 参数