【问题标题】:React native firebase multiple notification triggered in background in one event在一个事件中在后台触发本机 Firebase 多个通知
【发布时间】:2021-02-17 07:40:31
【问题描述】:

后台通知在一个事件中触发两次,不应该发生, 我无法检测到问题?我正在使用带有notifee的react native firebase进行通知..! 这是 useEffect 代码,我在其中取消订阅前台通知侦听器。

useEffect(() => {
    networkCall()
    fetchingUserData().then(() => {
        setIsLoading(false)
    })

    //
    // This is a function for receiving the notification message and displaying notification
    //
    async function onMessageReceivedFore(message: any) {
        onDisplayNotification(message);
        console.log('message received Foreground');
    }
    async function onMessageReceivedBack(message: any) {
        onDisplayNotification(message);
        console.log('message received Background');
    }
    //
    //This is for receiving notification onForeground
    //
    const unsubscribe = messaging().onMessage(onMessageReceivedFore);
    //
    //This is for receiving notification on background
    //
    messaging().setBackgroundMessageHandler(onMessageReceivedBack);

    return () => {
        console.log('component unmount');
        onNotificationInteraction()
        unsubscribe()
    }

}, [])

【问题讨论】:

  • 从 firebase 触发时您会收到两个通知?
  • 从 firebase 我得到了一个,但我猜它在我的代码中,这导致显示两个通知,我猜它是监听器的东西
  • 打开你的AndroidManifest文件并告诉我com.dieam.reactnativepushnotification.notification_foreground元数据的值
  • 我的清单中没有这样的标签
  • 您使用哪个库进行推送通知?

标签: android react-native firebase-cloud-messaging react-native-firebase


【解决方案1】:

我同时使用了 onForeground() 通知和 onBackground() 通知, 当我删除 onBackground() 通知时,onForeground 方法也在后台触发,所以我在一个事件中收到了两个通知......这不应该是这种情况,但现在似乎可以工作......强>

useEffect(() => {
    networkCall()
    fetchingUserData().then(() => {
        setIsLoading(false)
    })

    //
    // This is a function for receiving the notification message and displaying notification
    //
    async function onMessageReceivedFore(message: any) {
        onDisplayNotification(message);
        console.log('message received Foreground');
    }
    //
    //This is for receiving notification onForeground
    //
    const unsubscribe = messaging().onMessage(onMessageReceivedFore);

    return () => {
        console.log('component unmount');
        onNotificationInteraction()
        unsubscribe()
    }

}, [])

【讨论】:

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