【问题标题】:How to set reaction to tapping the notification in react-native?如何设置对在 react-native 中点击通知的反应?
【发布时间】:2019-01-04 12:37:30
【问题描述】:

我希望应用程序在点击通知后打开正确的视图。

我试图设置 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 反应原生:0.55.4 节点-v v8.9.3

我希望当我点击通知时会显示警报,但没有任何反应。

【问题讨论】:

    标签: javascript android firebase react-native push-notification


    【解决方案1】:

    解决方案:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多