如何解决在一个事件中在后台触发本机Firebase多个通知
在一个事件中两次触发了后台通知,这种情况不应该发生, 我无法检测到问题?我正在使用带有notifee的react本地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()
}
},[])
解决方法
我同时使用了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()
}
},[])
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。