我希望应用程序在单击通知后打开正确的 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/