-
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
[🐛] Bug Report Title - Data only notifications on android don't arrive when app is closed (EXPO) #8443
Comments
Hey there, can you show me a usage example of how you are using the background handler? |
Here is my handler at the top of my root setBackgroundMessageHandler(
messaging,
async (message: FirebaseMessagingTypes.RemoteMessage) => {
if (!message.notification) {
try {
await notifee.incrementBadgeCount();
await handleBackgroundMessage(message);
} catch (error) {
console.error("Error displaying notification:", error);
}
}
return Promise.resolve();
}
); As instructed in the docs, always return a resolved promise.
|
@MichaelVerdon , are there other informations you'll need on this?. It's a bug that needs to be fixed on my end 🙏 |
Hi there, i am currently investigating it. My testing app refused to work yesterday but it is all good today. 😄 |
I reformatted the JSON you send in the FCM so it was readable and I could scan for that key on a hunch. I don't see it |
Hey there, I did receive a notification whilst the app was in a terminated state and it opened the app. It did not work until I put this in my AndroidManifest (registering the service): https://firebase.google.com/docs/cloud-messaging/android/client
And you need to use this method getInitialNotification:
https://rnfirebase.io/reference/messaging#getInitialNotification I will warn you that it has been a bit flaky and I've observed messaging can be flaky with these things across other platforms making me think if it is an Android-Firebase native issue |
Also make sure there is a notification in your payload, I don't think data-only works. What purpose do you need it to be data only? |
That's not true - data-only on android works fine. iOS is very problematic and at the whim of the OS as to whether it will deliver or not - it will sometimes, enough to trick you into thinking it's reliable when it isn't - but android data-only works great in my experience |
You shouldn't need to do that, during AndroidManifest merge, that is added by the android gradle build process into the final combined AndroidManifest for the app, coming from this chunk here: react-native-firebase/packages/messaging/android/src/main/AndroidManifest.xml Lines 18 to 25 in c0c5054
To put that in the app-level AndroidManifest is to basically duplicate it - if you open an app with react-native-firebase messaging integrated and check the "Combined" AndroidManifest tab you should see it in there, merged in automatically I've never had to manually put this in my apps - so I suspect a test methodology error somehow when it had a negative delivery test result without it |
Thanks for clarification @mikehardy I still think it might be worth trying anyways as I managed to get it to work on my end doing that but on the other hand, I don't think I needed to do that with FlutterFire 🤔 |
Honestly, i think the formatted payload looks different from the initial. This is the correct payload the app receives{
"originalPriority": 1,
"priority": 1,
"sentTime": 1744117869665,
"data": {
"notifee": "{\"title\":\"string\",\"body\":\"string\",\"data\":{\"additionalProp1\":\"string\",\"additionalProp2\":\"string\",\"additionalProp3\":\"string\"},\"deepLink\":\"string\",\"imageUrl\":\"string\",\"type\":\"MEDICATION_REMINDER\"}",
"type": "MEDICATION_REMINDER",
"body": "string",
"title": "string",
"additionalProp3": "string",
"additionalProp1": "string",
"additionalProp2": "string",
"imageUrl": "string"
},
"from": "688826572618",
"messageId": "0:1744117869689285%2bc11c71cad56011",
"ttl": 259200,
"collapseKey": "string"
} Our api uses the firebase admin sdk in java, and we are setting the priority for every data message payload that is sent over. |
This is our snippet on the backend using the firebase admin private AndroidConfig buildAndroidConfig(PushNotificationRequest request) {
return AndroidConfig.builder()
.setPriority(AndroidConfig.Priority.HIGH)
.setCollapseKey(request.getTitle())
.setDirectBootOk(true)
.setTtl(259200000)
.build();
}
private ApnsConfig buildApnsConfig(PushNotificationRequest request) {
ApnsConfig.Builder builder = ApnsConfig.builder();
builder.setAps(
Aps.builder()
.setContentAvailable(true)
.build());
if (request.getDeepLink() != null) {
builder.putHeader("link", request.getDeepLink());
}
Map<String, String> apnsHeaders = new HashMap<>();
apnsHeaders.put("apns-priority", "5");
apnsHeaders.put("apns-push-type", "background");
builder.putAllHeaders(apnsHeaders);
return builder.build();
} this line I all looks like we are doing all the needful 😟 , but it just seem not to work on android. I appreciate the efforts and quick response from the team 👍 . Any idea what i'm doing wrong? @mikehardy |
Nope sorry, out of ideas. You might try https://dontkillmyapp.com/, make sure you don't have power saving on, check |
Leaving this here for anyone who gets into same situation.I was able to solve the problem by avoiding the problem all together 😄 . I initially opted for data-only messages due to some limitations on IOS > 17 #7548. But fixing it with the walk around introduced this issue on android. What i ended up doing?I still sticked to my data only message payload, but this time just for IOS. and i added notification key to the payload for android, and this solved my issue. Thanks @mikehardy and @MichaelVerdon for the support 👍 |
interesting - usually it is the other way around, data-only works well for android in my experience but on ios they are problematic I want to emphasize that in my experience on iOS data-only messages will show up for you, the developer, while you are testing with your device plugged in in the app you use all the time (since you are the developer). But iOS is very very very stingy with the power budget that it will give apps in response to messages, and if the device is too hot, low on battery at all, background refresh is off, or low power mode is on, or the user doesn't use your app all the time you will not get the FCM delivered to the iOS app as data-only Most people opt for notification block on iOS for this reason |
Thank you for this insight... I'll keep a close watch on this behaviour and also try a POC on a separate app to see how opting to the notification block turns out on IOS. Will update my findings here from time to time |
Issue
Describe your issue here
I'm using
@react-native-firebase/messaging
with@notifee/react-native
to handle notifications on my app... But android notifications don't arrive on devices when the app is closed.Key things to note
I did some research and bumped into #1238 but the conversations there seems quite old and i'm using Expo managed workflow.
Message Payload
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:# N/A
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
:android/app/build.gradle
:android/settings.gradle
:MainApplication.java
:// N/A
AndroidManifest.xml
: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: