-
Notifications
You must be signed in to change notification settings - Fork 4k
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
🐛 [FIREBASE_MESSAGING] iOS: message callbacks do not fire when push notification is sent via APNS token #4300
Comments
Hi @aytunch |
@markusaksli-nc from the console of the chat service I check the content_available flag but nothing changes. |
Does the background callback work if you send a notification through FCM? Such as {
"notification":{
"title": "This is the title",
"body": "This is the body",
},
"content_available": true,
"priority": "high",
"data": {
"id": 15,
"type": "comment"
},
"to": "FCM token"
} |
@markusaksli-nc Hi again:) I made several tests and below are the summary of the situation: When the client iOS app is on background, no matter what the content-available is set to, we only see the notification banner. onBackgroundMessage is never triggered. This is same with both FCM and 3rd party chat service(using APNS token) When the client iOS app is on foreground; |
My suspicion is that in this case The payload you sent seems to be meant for Firebase Admin SDK for Node.js. The FCM HTTP ref describes the property
The payload that I commented is what works for me when sending background messages.
With this it should at least work through FCM, however, I'm not sure how the third-party notification payload is handled so I can't offer any advice there. |
I also have a similar issue. I apologize if this is already mentioned if the documentation and maybe I have missed it, but do |
I'm facing the same issue on iOS. (when the app is in background or foreground it's working fine) |
I thought this plugin only handles messages if they contains the |
@acoutts Is there a Flutter package owned/maintained by Google for handling Push Notifications? I would be more than happy to use that one if it exists and works with any provider including Firebase. When I search pub.dev for push notification, the top results are However this is not a good design choice for Flutter and for us devs. Push notifications, imho are very essential for an app. And being forced to use multiple push notification packages which basically do the exact same thing(listening to a platform channel and getting a string from the OS) is an overkill. Also, these multiple similar packages usually have conflicts with each other and it is nearly impossible to maintain both when one has a breaking change. Right now, we are trying to build an app which we are working very hard on. We have a goal, even if the app is not successful, at least it will be able to showcase what Flutter is capable of. We had to face some hurdles about Video and Camera packages but now they are in a more stable condition. For push notifications, I can not say the same. Image in iOS still is not working. Documentation lacks a lot. And this fcm/apns token and being forced to use multiple push packages stalls us big time. Most of the big apps would need to talk to multiple push notification providers. I hope you guys can make things easier for your fellow devs. |
Wanted to bump this. I'm experiencing the same exact issues as @aytunch using Firebase Messaging v8.0.0-dev.14 where none of the handlers are being called when app is in the foreground. I have also confirmed that push notifications send properly via Firebase Cloud Messaging. The docs mention for iOS to add
This only actually allows notifications to appear when the app is in the background/terminated. However, when I tap the notification, the callbacks are not called appropriately. Can someone confirm that these handlers are supposed to be called on iOS the same way as on Android? Additionally, the content-available flag does not seem to make a difference here especially for alert messages. |
Any update about this ? |
@paod634 could you find a solution to this? |
The issue only applies to usage without Firebase because a special field, that is checked, is missing. You have two options: If you remove the if's then the onMessage function will also be called again. There are similar checks on the Android side, but it seems that Google is always adding a corresponding message_id and therefore everything is fine. See: https://github.com/FirebaseExtended/flutterfire/blob/ae683e5251673d089af7ff1c8d55db8724267901/packages/firebase_messaging/firebase_messaging/android/src/main/java/io/flutter/plugins/firebase/messaging/FlutterFirebaseMessagingPlugin.java#L242 I don't know why those checks were implemented on the iOS side, but it is definitely inconsistent that Android works out-of-the-box but iOS requires some "special" treatment. Maybe someone wants to make a PR which removes those if's and see if it gets merged. @BastienNOEL: Thanks for getting to the bottom of this! |
@paresy @BastienNOEL this is great investigation. What value should we set for As for option a, it seems it is hard to do because our 3rd party chat service sends them automatically without us having a chance to change the notification data object. So we are stuck with option b. @markusaksli-nc @Salakar is there a specific reason why iOS and Android behaves differently with |
We are just sending a static dummy value so the expression evaluates to true. As far as i have seen there is no further usage for the massage_id besides the existence verification. |
We are facing same issue, even foreground notification is working fine only in debug mode. Background never work in any mode. |
I have the same issue, How did you resolve that? @aytunch . Could you tell me ? Thanks |
@tungthanhcmc unfortunately they still haven't solved this issue. We are thinking of migrating to another BE solution. Reliable Push notifications is a must for a production app. Not being able to catch instances when a customer presses a PN is not acceptable. |
So sad. Did you try to edit native code? @aytunch |
My experience is probably outdated by a year or more at this point, but I ended up digging around in native code + other people's plugins (for months...really), cobbling together a solution that worked specifically for my coding style / project (really, it was rejected for merge into Firebase codebase, but it did work for my needs 😅). I recommend, unfortunately, to anyone having trouble, to do the same / get your hands dirty with some Xcode debugging and/or strategically placed log statements (remote phone-to-server logging, if you have to, as say when debugging opening notifications from terminated state). Worst case, you'll learn a ton about how iOS + Android handle incoming notifications. I used a combo of my own forks of FlutterFire and AwesomeNotifications on Flutter side, for which my admittedly messily forked repos / commits / PRs are at:
On backend (Python FastAPI), I used FirebaseAdmin, with a custom built series of Message objects (DataMessages + NotificationMessages, from which a number of other custom notifications inherited) that are translated into differently (likely mis)configured TL;DR -- Push notifications was one of the most convoluted features to work with in Flutter for me. I feel your pain. It took me months to get something working somewhat reliably. If I can help at least point you in the right direction, lemme know, though my knowledge at this point is probably wicked out of date if not buried underneath cobwebs in my brain. Shameless plug: If anyone is looking to help breathe life back into a Flutter / Python (FastAPI + SQLAlchemy + Pulumi) project, and likes the idea of hacking on real estate data either for fun or for the greater good (let's make buying a home / renting an apartment easier, cheaper and more fair for buyers/tenants and sellers/landlords around the world), hit me up ([email protected]). Would love to chat. |
Problem still exists. Still no "onMessage"-callback if app is active and "alert" is present in "aps". Checked line 490 in the file: As a quick fix I removed the condition: |
@russellwheatley Do you know why this condition is here? |
@Lyokone The |
@russellwheatley please correct me if I am misunderstanding something here
What is the reason for this? Our apps can receive push notifications from multiple sources. And why can we not rely on It seems like In our app, we use Firebase + 3rd party chat service. And in our Flutter app we want to use this plugin to catch all the notifications in a central place and move the app accordingly. For my current understanding; I want to request you guys to reconsider the |
Hello everyone, we’ve reviewed the issues opened for iOS background messages and we want to make our position clear. Android and iOS handle background messaging differently. The decision made by the iOS operating system whether messages reaches the relevant iOS event handler (and subsequently received by the Dart background messaging handler) is based on a number of criteria, such as: CPU usage, priority level (data-only messages are considered “low priority” by iOS, android does not), battery level, amount of messages being received by the app, background/terminated application state, etc. This is a fundamental difference between the platforms, and you need to be aware of them when designing your application. One solution suggested for iOS data-only messages unreliability has been to add a NotificationExtension. But this will still not create parity with Android as you will still have to include a notification with your message (therefore not data-only). It will still render the original notification if you do not update/mutate the notification that comes through the system in a timely manner. We are not currently considering this as a solution due to these limitations. We also will not support non-FCM messages from third party packages. We specifically only support messages received from the Firebase APIs since we cannot guarantee that messages received from third party packages will not have any unintended side-effects on other Firebase products such as messaging delivery reporting and Analytics data. To help us triage and locate genuine issues that need to be addressed we have created a specific issue template for iOS background messages. If you believe you still have an issue that needs to be addressed, please create a new issue following this template. I will be closing this issue in favor of raising a new issue with the new template above. This template will help you provide us with all the information we need to investigate a potential issue with background messaging on iOS. |
@russellwheatley Then may I ask why does If 3rd party notifications are received by |
Bug report
Describe the bug
On iOS devices,
I upgraded to Firebase Messaging v8.0.0-dev.9
With it, I was able to use getAPNSToken() and successfully send this 64bit hexadecimal to a third party chat service.
When I send a push notification from the third party chat service console and app is on the background, iOS shows the notification banner.
My code looks like this:
The
onMessageOpenedApp
andonBackgroundMessage
functions do not get triggered when a notification is sent through the third party chat service while the app is in the background.However
onMessageOpenedApp
triggers when I send a message from Firebase Cloud Messaging. Note thatonBackgroundMessage
does not fire even with Firebase Cloud Messaging.Also the
onMessage
function does not get triggered when a notification is sent through the third party chat service while the app is in the foreground.Steps to reproduce
Steps to reproduce the behavior:
getAPNSToken()
to get the native token for iOS.onBackgroundMessage
is not being triggered.onMessage
is not triggered and the notification is totally omitted by Firebase MessagingExpected behavior
We should receive the notifications send to our app thorugh
onMessage
andonBackgroundMessage
no matter if they are sent using APNS or FCM token.Additional context
Add any other context about the problem here.
Flutter doctor
Run
flutter doctor
and paste the output below:Click To Expand
Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:Click To Expand
The text was updated successfully, but these errors were encountered: