-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[🐛] 🔥 onMessage callback gets triggered multiple times on iOS 18 #7979
Comments
Haven't been able to test on iOS 18 yet, I don't have Xcode 16. I tested on iOS 17.6, and I only received one message. I'll circle back to this once I have Xcode 16. |
Hello! Yes, I experienced the same running on iOS 18. I've tried some workarounds like this one:
Basically it saves the latest received identifier of the push notification and skip it if it is the same, but I've received some other non-ui pushes in-between that changed the latest identifier, like: UI Push - Identifier: A So the push with 'B' identifier will the logic above to fail. Another workaround, would be to have in memory the list of all the push identifiers and check if they were previously reported. But this is not a good idea because it can be a huge list in memory. But this is more a patch than fixing the real bug. Any other suggestions would be welcome! Ah! This is happening when receiving the push notification while the app is in foreground. |
Btw, looks like to be an issue in iOS 18 Beta investigated by Apple: https://developer.apple.com/forums/thread/762412?answerId=800720022#800720022 And here is a possible patch/workaround: https://developer.apple.com/forums/thread/762126?answerId=800296022#800296022 So here is the updated code to filter out pushes that we don't use to show in the UI and to save the latest id to filter duplicated pushes:
|
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
I have the exact same issue since I upgraded to xcode16.0 and iOS18 on my physical device. I ensured that my listener only subscribes once, but it still fires twice every time. On other devices with iOS17 it is working as expected. |
@smfunder Hello mate. I have pasted this code inside AppDelegate.m file and build the app. not working in my case can you please help me in this? Thanks in Advance 🫡 |
I'm facing the same issue, any update? |
I am also facing this issue. macOS: 15.0.1 (24A348) "react-native": "0.74.5", |
Same issue ... thats driving me crazy. I almost lost my mind because I was searching for the issue on my side the whole time. |
I am also using ios 18 for me in iOS foreground notification was mutiple times. Had fixed using mmkv workaround.
|
I've created a temporary fix for this issue, and hope it will help react-native-firebase-ios18-fix Check the comments in the code if you are using bare react-native (not expo) |
@xerdnu definitely appreciate the help, however:
That is not the problem, that is the symptom :-), what is the problem? Have you checked in to firebase-ios-sdk to see if anyone is chatting about this on their issues list? Have you tried instrumenting the native code in the messaging module here with extra log statements and then watch Console.app on a real device as it receives messages to see what is going on ? Would be very interesting to know the actual cause - likely there is some easy fix in the code if someone has time to add the log statements and watch a message delivery to see what code is running. I'd love to merge a PR for this but haven't had time to look at it myself and won't for a while unfortunately |
You are 100% correct and i did not mean to make it sound that rnfirebase is the core issue for certain. I updated the readme to make this very clear :-) Unfortunately i dont have the time to dive into this any deeper right now as i am just in the release stage of my own app so i needed a "quick fix" for the problem that i decided to share as a temporary solution as this issue caused big problems for me on iOS 18. Hopefully it can help someone else aswell until it gets fixed. Best regards! |
I actually suspect RNFB could be the core issue 🧐😅 |
This worked for me because only the last delivered notification was being displayed twice. // This holds last processed notification
const lastDisplayedMessageIdRef = useRef < string | undefined > (undefined);
useEffect(() => {
const unsubscribeOnMessage = messaging().onMessage(remoteMessage => {
if (!remoteMessage) {
return;
}
// Message is already processed
if (lastDisplayedMessageIdRef.current === remoteMessage.messageId) {
return;
}
displayNotification(remoteMessage);
});
return () => {
unsubscribeOnMessage();
};
}, []); |
you are not setting the last message id. |
Issue
On devices and simulators running iOS 18, the
onMessage()
callback gets called two or more times. The issue does not appear on Android or on iOS devices running 17.5 or below.I've verified, that the
onMessage()
call itself is only done once, so there should not be multiple listeners active.The remoteMessage payload is
notification+data
.Devices tested, where the bug is present:
Devices tested, where the bug is not present:
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:AppDelegate.m
:Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:// N/A
AndroidManifest.xml
:<!-- N/A -->
Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:20.4.0
Firebase
module(s) you're using that has the issue:messaging
TypeScript
?Y
,5.0.4
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: