-
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
[🐛] IOS - Background notification received as foreground notification too #7836
Comments
Also had the case of getting a white screen on ios. I guess is it because of HeadlessCheck function HeadlessCheck({ isHeadless }) {
if (isHeadless) {
// App has been launched in the background by iOS, ignore
return null;
}
return <App />;
}
AppRegistry.registerComponent(appName, () => HeadlessCheck); As a user, i open the app the same time the iOS launch it in background to run the |
🤔 would be interesting to see all the handlers in play, also the JSON (or code that generates it) for the FCMs that trigger the problem - Note that in all cases I'm aware of, if an iOS app is not foreground and JSON has notification key, the firebase-ios-sdk library will post a notification. So you must not post your own in that case later or you will double notify. If you want to take control of behavior of notification posting for FCM with notification block while iOS app is in background you need to implement a notification extension helper, as documented in notifee repo |
I have the both handlers posted in the first comment. private Message getMessage(String token, String title, String text, Map<String, String> data, long ttl,
String sound, String channelId) {
Notification notification = null;
AndroidNotification androidNotification = null;
if (text != null || title != null) {
notification = Notification.builder().setBody(text).setTitle(title).build();
androidNotification = AndroidNotification.builder()
.setBody(text)
.setTitle(title)
.setSound(sound)
.setColor(COLOR)
.setIcon(ICON)
.setChannelId(channelId)
.setPriority(AndroidNotification.Priority.HIGH)
.build();
}
HashMap<String, String> apnsHeaders = new HashMap<>();
apnsHeaders.put("apns-expiration", String.valueOf(ZonedDateTime.now().plusSeconds(ttl).toEpochSecond()));
ApnsConfig apnsConfig = ApnsConfig.builder()
.setAps(Aps.builder()
.setContentAvailable(true)
.setSound(sound)
.setAlert(ApsAlert.builder().setTitle(title).setBody(text).build())
.build())
.putAllHeaders(apnsHeaders)
.build();
AndroidConfig androidConfig = AndroidConfig.builder()
.setTtl(ttl)
.setPriority(AndroidConfig.Priority.HIGH)
.setNotification(androidNotification)
.build();
if (data == null) {
data = new HashMap<>();
}
data.put("reload", "true");
return Message.builder()
.setNotification(notification)
.setToken(token)
.setAndroidConfig(androidConfig)
.setApnsConfig(apnsConfig)
.putAllData(data)
.build();
}
The idea is that I dont want to post it if the the firebase sdk already posted it. But in reality the firebase sdk post it and when the user opens the app the onMessage is triggered with the same notification and i have no idea how do i know that the firebase sdk didnt showed it already. I was expecting that ones it was posted its done with it but it seems that I get a race condition somehow (the notification is not discarded from some internal queue and it sends it to onMessage listeners) Edit: Not sure if it is important but we use 2 custom sounds. One is 1 second long and one is 27 seconds long |
Any news here - I have the same exact issue? |
i faced the same issue |
I am also facing the same issue. |
I'm facing the same problem. |
I have facing this issue before in 4 Apr, i am just using redux to save the remote message from the onNotificationOpenedApp function and then compare with the remote message from the onMessage function, if the messageId are the same, then not to show the notification when the app is opening. After few months, my client reported that they encounter the same issue again, but when i trying to encounter the issue, everything is normal. They was just sent the push notification on the last day and open it on the next day, the notification will show again when the app is opening However, i have update the react native version from 0.71.5 to 0.72.13 for my apps before, so it seems the issue still happening on different version. And i am using "@react-native-firebase/messaging": "18.3.0", |
I just tested this, I didn't see this behaviour. Need an mcve to demonstrate this issue. |
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. |
Didnt have time to make a mcve, but its still actual |
I am facing the same issue , did any one find the solution? |
I am facing the same issue, but I noticed this happens only on iOS 17. On iOS 16 and iOS 18 it works fine. I'm desperate. Did anyone find a workaround by any chance? |
@xLorena same issue I am facing. iOS 18 works fine but iOS 17 has issue receiving notifications until the app is opened. |
I am also facing the same issue. I have app in background and notification come. When I open the app after notification then onmessage fired and show foreground notification again. |
If this is only happening on iOS 17 but working on iOS 18 / 18.1+ it sounds like a platform bug that is resolved (and iOS users typically update quickly so it should actually resolve in user base as well). This likely won't receive priority here, and a workaround such as that proposed for the recent "iOS 18 delivers message twice" issue (which resolved in iOS 18.1) may be the best way to move forward Here is an example workaround that follows the basic idea of "let's save the last sent message, now when we get a message, is it the same as the last sent one? If it is the same skip it, if it is not, then save this one and post it". The idea may be extended to save multiple messages as needed #7979 (comment) |
@mikehardy I can confirm that it is not working on iOS 17 and iOS 18. Because I tested it on iOS 18.0.1 and 18.1 and it is not working. I also tested it on iOS 17.6 and same results. I am aware of the saving last message workaround but again the issue is we are still struggling with background event handler issue. Sometimes when I get notifications when app is killed then background event handler didn't fired. |
@ankitpoplify going to have to echo Russell here. This looks tough to reproduce, but certainly no progress can be made without a concrete reproduction as it is pretty subtle Need an MCVE Can use https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh to create a skeleton. Make all code fit in App.tsx, include a shell script that uses the FCM REST API to post a specific message given a firebase project API key and device token so the behavior can be triggered for inspection |
facing the same issue on IOS 18.2. Has anyone found a solution yet? |
Is there anyone who handling this issue by iOS Native Code? |
Issue
We are encountering an issue where iOS users occasionally see twice the push notifications. First time the notification is displayed by the OS as we send a push notification with the
notification
key (not data only). The second time the notification is displayed using notifee but the problem is that we receive the same notification inmessaging().onMessage
after the app is opened.We have configured a setBackgroundMessageHandler. We send a push notification with firebase admin sdk from our backend. The notification has title, body and data, content_available is true.
We also have a listener for foreground push notification which looks like this:
Steps we use to reproduce (not consistently):
Remarks:
If you close the phone screen on step 1, the chance to reproduce it seems higher
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:e.g. 5.4.3
Firebase
module(s) you're using that has the issue:e.g. Instance ID
TypeScript
?Y/N
&VERSION
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: