首页 > 解决方案 > onNotificationOpened 方法未在反应本机 Firebase 中被调用

问题描述

我在我的 react native 项目中使用 react-native-firebase 进行通知,我试图从 componentDidMount 方法调用 onNotificationOpened 和 getInitialNotification 但这两种方法没有被调用,任何建议将不胜感激

this.removeNotificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
    console.log('onNotificationOpened AppJS :', notificationOpen)
    const { action, notification } = notificationOpen
    let item = JSON.parse(notification.data.body)
    console.log('onNotificationOpened AppJS : body ', item)

    console.log('onNotificationOpened AppJS : action ', action)

})

firebase.notifications().getInitialNotification()
    .then((notificationOpen: NotificationOpen) => {
        if (notificationOpen) {
            console.log('getInitialNotification AppJS : Shoeb ########: ')
            // App was opened by a notification
            // Get the action triggered by the notification being opened
            const { action, notification } = notificationOpen
            let item = JSON.parse(notification.data.body)
            console.log('getInitialNotification AppJS : item ', item)
            console.log('getInitialNotification AppJS : action ', action)

        }
    })

标签: react-nativereact-native-firebase

解决方案


推荐阅读