-
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] Background handler never invoked on iOS #6290
Comments
Hi @mikeroneer |
I'm facing the same issue here. I've created a test Cloud Function just to test again, but it didn't work:
My handler:
Seems like everything is ok on my setup, I'm receiving notifications, only silent notifications doesn't work in iOS in background/terminated. |
I was having this issue too. Just fixed by deleting the old key "FirebaseAppDelegateProxyEnabled" from my info.plist. My json notification payload contains both notification, data and the apns payload with content-available : 1. |
Thanks for the help! |
Any updates on this? |
Also looking forward for an update to this. Having the exact same issue/behavior on same test device and plugin version. Notification works just fine in app foreground. However, when the app is in background, the notification appears in the notification center but my background handler function by the pubspec firebase_core: ^1.2.1
firebase_messaging: ^10.0.1 flutter doctor [✓] Flutter (Channel stable, 2.2.1, on macOS 11.2.3 20D91 darwin-x64, locale en-US)
• Flutter version 2.2.1 at /Users/aaa/Documents/flutter
• Framework revision 02c026b03c (10 days ago), 2021-05-27 12:24:44 -0700
• Engine revision 0fdb562ac8
• Dart version 2.13.1
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/aaa/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5, Build version 12E262
• CocoaPods version 1.10.1
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.56.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.23.0
[✓] Connected device (1 available)
• Nico’s iPhone (mobile) • 00008030-000A5C843E86402E • ios • iOS 14.5.1
! Doctor found issues in 1 category. |
Hi @markusaksli-nc, I've updated the initial thread. |
Facing same issue and almost having same configurations. |
Interestingly, these are my findings on real phones: iOS14.5.1 -> anyone with similar findings? |
Well firstly
That being said, you mentioned that the call is not fired when the app is in the background as well? Have you tried checking the device logs for any relevant errors? Have you requested and allowed permissions on the device? |
Yup all permissions granted. Same code base for all 4 devices. Oops forogt to mentioned for 13.7 and 13.1.3 notification immediately shown upon launching app from background. |
We only have a testing device with iOS 14.5.1, where @markusaksli-nc all permissions have been granted, yes. |
Well, I haven't been able to reproduce this but based on the number of reports I'm going to label this. Please try to go through the device logs (console app on mac) to see if there are any relevant messages that could point to an issue in handling the message. |
i actually receive the notification even when the app is terminated. |
same issue here. so i tried with example source in flutterfire gitbub repository i changed like below files with our info
but it doesn't worked too. i guess you have tested the example source many time. i sent fcm message with cloud messaging page firebase console (https://console.firebase.google.com/u/0/project/[Project-Name]/notification) flutter doctor
my iOS device os version is 14.6 |
@HaveANiceDay33 We have ditched the idea of handling notifications on iOS silently and we made a native notification extension on iOS to handle rich notifications with mutable-content tag, everything is going smooth so far with notification localization and click handling on Flutter side. Sadly this is the only way so far to be able to receive notifications reliably on iOS. I know maintaining two code bases for the same scenario for different platforms is not the ideal solution especially if you have chosen Flutter in the first place, but I encourage everyone facing the same problem not to waste their time trying to fix it if they're tight on the delivery schedule. |
Can you show the extension code? Now you can always run flutter code after receiving a FCM notification, even when the app is killed by the user? |
Can anyone please suggest to me any workaround solution specific to ios for this issue? |
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
background handler doesn't executed for me else, but these codes does. Anyone can try these methods to get codes executed when app is terminated and / or background |
@elsystm can you please help me with that native implementation? Can you at least share some code samples or some resources to help us with that? Thanks by the way! |
Hey @mikeroneer. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically. If you have more information that will help us get to the bottom of this, just add a comment! |
Issue continues on iOS 15.5. and |
any updates about it? |
This answer helps me. Just use getInitialMessage |
Just to be clear on this issue; I have tested background message handling on iOS multiple times, and it hasn't failed to work. I've created a PR for updating the messaging example app with a set of instructions for you to follow. I would be grateful if you are experiencing an issue, if you could test the example app by following the instructions, and let me know if you're able to receive messages in your background handler. I will ultimately be closing this issue as it doesn't serve any purpose except to confuse users about the state of |
Me also faced the same issue. To fix this did the following changes.
Step 2
Now able to receive data only notification and |
+1 |
It doesnt work on termination mode all the time, it might work for 1-2 hours, then it will stop completely |
@rulefahd if you are talking about iOS, I agree that data-only messages would stop getting received. but for the android part, you have to follow a specific payload structure to be able to keep receiving the notifications in the terminated state even. Here is an example that is working for me on android. I have tested it myself.
|
@rulefahd as for iOS, there is no easy way of doing this. The bottom line is that you cannot achieve an always working terminated state notification using FCM. You would have to use a native Swift or Objective-C implementation to be able to do that. I implemented that using PushKit as I was doing this for call implementation. if you need anything else, please feel free to ask. |
At last it works with the last release, I tested successfully with next json body
|
It works when you throw it down, yes, but when the application is completely closed, the notification does not come at all. |
I see PR #9292 fix the problem is it available in pub dev or not yet? |
firebase_messaging 12.0.2 is the latest version but now I'm getting the same error. I hope the problem is fixed soon, it's very annoying. |
Yes i don't this bug fixed in change log |
@hatemragab the PR is just an update to the example app to show the background handlers work as intended. There’s nothing to release. The example app is updated so users can see that the API works and if there is a problem, it is something wrong with their setup. If you look at the PR, all the files updated are in the example/ directory and also a documentation update. |
I also facing this issue. |
Bug report
Describe the bug
According to https://firebase.flutter.dev/docs/messaging/usage/#message-types, the background handler should be invoked for notification messages, data messages or a combination of both when the app is in the background or terminated. In our project, it is not invoked in any of those cases. For the sake of completeness it is worth to mention that the
onMessage
stream fires properly when the app is in foreground and also the notification handled by the FCM-SDK is shown when the app is in background/terminated. It's just theonBackgroundMessage
which is never invoked.We are aware of the
content_available
flag, however, the issue does not just relate to silent (data only) messages.Steps to reproduce
Steps to reproduce the behavior:
_firebaseMessagingBackgroundHandler
Expected behavior
onBackgroundMessage
is invoked when the app is in background or terminated.Sample project
Edit: Payload (suggested by @markusaksli-nc)
We have tried quite a lot of different payload combinations, with both, containing a data object only and a notification object respectively. We have also tried addressing the recipient via a topic (which is our intended use case) as well as with the unique device token. Background modes (Background fetch and Remote Notifications) are enabled too. On the server side, we are using the Java SDK, however, we have also tried sending a POST request directly via Google's OAuth 2.0 Playground.
The following indicates a sample payload:
Additional context
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: