gpt4 book ai didi

react-native - React Native Android后台处理程序中重复的fcm推送通知

转载 作者:行者123 更新时间:2023-12-05 03:27:20 24 4
gpt4 key购买 nike

我使用 rnfirebasenotifee 开发了 React Native 应用程序来发送推送通知。前台工作正常,消息仅显示一次。但是后台通知显示了两次,其中一个是来自 messaging().setBackgroundMessageHandler 的,另一个是 android 的默认推送通知。第一条消息来自默认推送通知,下一条消息来自 firebase 消息传递。那么如何删除android默认的推送通知呢?我还检查了第一个默认通知未使用 firebase 消息传递和 notifee。它来自 React Native 之外,就像 Android 的原生推送通知

See this image

最佳答案

您看到的通知很可能是来自 firebase 的通知和来自 Notifee 的通知。在我的项目中,我通过 firebase.messaging().onMessage 处理来自 firebase 的通知,并且在这个监听器中,我使用 Notifee 显示本地通知,以便通知显示在前台。

async showNotificationInForeground(message: FirebaseMessagingTypes.RemoteMessage) {
const { messageId, notification, data } = message
const channelId = await Notifee.createChannel({
id: messageId,
name: 'Pressable Channel',
importance: AndroidImportance.HIGH,
})

await Notifee.displayNotification({
title: notification?.title || '',
body: notification?.body || '',
data,
android: {
channelId,
importance: AndroidImportance.HIGH,
pressAction: {
id: messageId,
},
smallIcon: 'ic_stat_name',
localOnly: true,
},
})
}

但是,我正在调用这个 showNotificationInForeground 方法来在 firebase 的后台和消息监听器上显示本地 Notifee 通知,即: firebase.messaging().onMessagefirebase.messaging().setBackgroundMessageHandler

所以我最终所做的只是在 onMessage 监听器中调用 showNotificationInForeground 方法,而不是在 setBackgroundMessageHandler 中,这导致显示本地前台通知,后台 Firebase 通知。

如果您的情况并非如此,您很可能在 AndroidManifest.xml 文件中注册了一个额外的通知接收器,这导致了重复

关于react-native - React Native Android后台处理程序中重复的fcm推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71507734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com