Closed mikeroneer closed 1 year ago
Hi @mikeroneer Could you provide the exact payload you are sending through FCM? Thank you
I'm facing the same issue here. The background handler on iOS never worked for me in any version. (now I'm using 10.0.1) I have tried to implement a feature on my app that I need to use the background handler but it's working only for Android.
I've created a test Cloud Function just to test again, but it didn't work:
await admin.messaging().sendToDevice(
'token',
{
data: { remoteConfig: 'stale' },
},
{ contentAvailable: true, priority: 'high' }
);
My handler:
void main() {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(firebaseBackgroundMessageHandler);
//etc
}
Future<void> firebaseBackgroundMessageHandler(RemoteMessage message) async {
print("Message received");
await Firebase.initializeApp();
final _notificationService =
NotificationService(StorageRepository(), UserRepository());
await _notificationService.onMessageReceived(message);
}
Seems like everything is ok on my setup, I'm receiving notifications, only silent notifications doesn't work in iOS in background/terminated. Background Modes (Background fetch and Remote Notifications) are enabled too.
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. Don't know if this is your case but just leaving something that helped.
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. Don't know if this is your case but just leaving something that helped.
Thanks for the help! Unfortunately my Info.plist doesn't contains this key :/
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 FirebaseMessaging.onBackgroundMessage
was not triggered.
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 @mikeroneer Could you provide the exact payload you are sending through FCM? Thank you
Hi @markusaksli-nc, I've updated the initial thread.
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
FirebaseMessaging.onBackgroundMessage
was not triggered.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.
Facing same issue and almost having same configurations.
Interestingly, these are my findings on real phones:
iOS14.5.1 -> onMessage
and onBackgroundMessage
works; onBackgroundMessage
doesn't invoke when app terminated
iOS14.6 -> onMessage
and onBackgroundMessage
works; onBackgroundMessage
doesn't invoke when app terminated
iOS13.7 -> onMessage
works; onBackgroundMessage
doesn't invoke
iOS13.1.3 -> onMessage
works; onBackgroundMessage
doesn't invoke
anyone with similar findings?
Well firstly onBackgroundMessage
is not expected to work when the app has been terminated on iOS as this is a native limitation. This is also documented in https://firebase.flutter.dev/docs/messaging/usage#receiving-messages
On iOS, if the user swipes away the application from app Switcher, it must be manually reopened again for background messages to start working again.
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?
Well firstly
onBackgroundMessage
is not expected to work when the app has been terminated on iOS as this is a native limitation. This is also documented in https://firebase.flutter.dev/docs/messaging/usage#receiving-messagesOn iOS, if the user swipes away the application from app Switcher, it must be manually reopened again for background messages to start working again.
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.
Interestingly, these are my findings on real phones:
iOS14.5.1 ->
onMessage
andonBackgroundMessage
works;onBackgroundMessage
doesn't invoke when app terminated iOS14.6 ->onMessage
andonBackgroundMessage
works;onBackgroundMessage
doesn't invoke when app terminated iOS13.7 ->onMessage
works;onBackgroundMessage
doesn't invoke iOS13.1.3 ->onMessage
works;onBackgroundMessage
doesn't invokeanyone with similar findings?
We only have a testing device with iOS 14.5.1, where onBackgroundMessage
is never invoked, neither when the app is in background nor terminated (which is another thing to discuss anyways).
@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. But the second one ! the first one is always missed, gone then after the second one i always receive them
same issue here. i tried with various methods whatever i can search.
so i tried with example source in flutterfire gitbub repository
i changed like below files with our info
- GoogleService-Info.plist
- Runner.pbxproj (Bundle Identifier)
but it doesn't worked too.
i guess you have tested the example source many time. so i wonder that i missed some apns setting or fcm settings. what should i check?
i sent fcm message with cloud messaging page firebase console (https://console.firebase.google.com/u/0/project/[Project-Name]/notification)
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale ko-KR)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] VS Code (version 1.55.2)
[✓] Connected device (5 available)
my iOS device os version is 14.6
@rouddy Please open xCode and check the settings there, Please check if push notifications capabilities are added properly. I noticed after upgrade to flutter 2.2
I lost some settings of the app or may be i tried to fix something with flutter create .
command and later i noticed my app push notification settings are not there in capabilities.
Basically on my side it is not working in release mode in ios in the lastest update of firebase_core: ^1.3.0 and firebase_messaging: ^10.0.2
@rouddy Please open xCode and check the settings there, Please check if push notifications capabilities are added properly. I noticed after upgrade to
flutter 2.2
I lost some settings of the app or may be i tried to fix something withflutter create .
command and later i noticed my app push notification settings are not there in capabilities.
as i mentioned lately tested project is flutterfire official github repository's firebase messaging library example project. for the just in case i checked the setting and they are checked.
i think that cause of this problem is maybe in the outside of the code.
For my case, looks like if I make a release build to my device, it doesn't invoke the background handler when the app was running in the background and the phone is locked, and the background handler will get invoke immediately if I manually start the app after unlocking the phone.
but if it's a debug build and deployed to my device, it does invoke the background handler no matter what. I am using firebase_core 1.4 and firebase_messaging 10.0.4
+1 not, backgroundHandler is not being called when app is terminated or in background
Anyone knows to which version of firebase_messaging we can rollback to make it work?
+1 confirm that this simple piece of code (NodeJS server side): …
message = {
notification: {
title: title,
body: body
},
data: data,
tokens: devicetokens
};
firebase.messaging().sendMulticast(message).then(function(response) {
console.log(response.successCount + ' messages were sent successfully');
})["catch"](function(error) {
console.log(error);
});
is working perfectly on Android (both foreground and background notifications are received as expected) while on iOS is missing background fetch. Run many different configurations of message object (with/without “apns/headers”, with/without “notification” property, with/without contentAvailable/content-available) with no success. Note: we got background callback to work by deleting “notification” property but just once then stopped being fired…this happens just in release mode while in debug everything is working pretty well. Suspect that is something related to translations of FCM to APNS since we put low-level didReceiveRemoteNotification on debug and noticed that is never invoked on background message.
@angeloborrelli thanks for the detailed explanation. The problem we are facing with iOS is when a user opens the app clicking a push notification while the app is in terminated or background state.
FirebaseMessaging'sonMessageOpenedApp
and getInitialMessage
does not fire when our app is opened by a push sent using APNS by a 3rd party chat service. The problem is not with the chat service since we tried all possible combinations manipulating the payload as you stated and we even tried another service just to make sure.
So basically we can not navigate a user opening the app by pressing a chat push notification to the related chat detail page. This is a huge flaw in my opinion.
I don't know if this is the case for any of you, but in mine, the problem was on the server side that sent my notifications. The apns settings were missing.
Reference: https://firebase.flutter.dev/docs/messaging/usage/#low-priority-messages
I just changed the background
apns type to alert
, and then my onBackgroundMessage
was called properly.
Versions Flutter: 2.2.1 firebase_messaging: ^10.0.2
Message firebaseMessage = new Message()
{
Token = userToSend.PhoneToken,
Notification = new Notification()
{
Title = "Title",
Body = "Message",
},
[...]
Apns = new ApnsConfig()
{
Aps = new Aps()
{
ContentAvailable = true,
},
Headers = new Dictionary<string, string>()
{
{ "apns-push-type", "alert" },
{ "apns-priority", "5" }
},
},
[...]
};
I don't know if this is the case for any of you, but in mine, the problem was on the server side that sent my notifications. The apns settings were missing.
Reference: https://firebase.flutter.dev/docs/messaging/usage/#low-priority-messages
I just changed the
background
apns type toalert
, and then myonBackgroundMessage
was called properly.Versions Flutter: 2.2.1 firebase_messaging: ^10.0.2
Message firebaseMessage = new Message() { Token = userToSend.PhoneToken, Notification = new Notification() { Title = "Title", Body = "Message", }, [...] Apns = new ApnsConfig() { Aps = new Aps() { ContentAvailable = true, }, Headers = new Dictionary<string, string>() { { "apns-push-type", "alert" }, { "apns-priority", "5" } }, }, [...] };
Yep, tried this configuration too but no success. flutter 2.2.3 (stable channel) firebase_core: ^1.4.0 firebase_messaging: ^10.0.4
My problem is (iOS) : If i'm using push type 'alert': app receive push notification foreground. but in background / terminated, background handler won't get call. If i'm using silent push with content-available: true: app triggers background handlers when my app in background perfectly fine. but because it is silent push, it won't receive any notification when the phone in 'deep sleep'.
Hope i can get a way to safisfy both cases.
firebase_core: 1.3.0 firebase_messaging: 10.0.3
I noticed last night, after a bit of a deep dive into iOS notifications code, that issues can crop up between separate Flutter pub packages if they both try to claim themselves as the delegate for UNNotificationCenter
in Swift. With that in mind, @k3vinb0ss, it might be helpful for debuggers to know your full pubspec.yaml list, as there could be conflicting packages. For example, I had an issue with code here where awesome_notifications
, a local notifications package, was fighting with firebase_messaging
for delegation control, amongst other issues.
@tek08 is there way for us to check if any of the packages we use in our pubspec.yaml uses UNNotificationCenter
?
@aytunch -- I delve into package's code either by looking (or grepping) through each's source code published on Github, or under the ios
folder of your Flutter directory, there is a .symlinks
folder which points to a folder containing each of the package's root directories.
hi @tek08, I'm using flutter_local_notifications plugins to display local notifications and it required UNUserNotificationCenter delegate. Don't you think it cause my background handler don't get call with "alert" type notification ? I'm also using VoIP Push.
here is my AppDelegate.swift
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, PKPushRegistryDelegate {
var deviceToken: String = ""
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: nil)
// Set the registry's delegate to self
voipRegistry.delegate = self
// Set the push type to VoIP
voipRegistry.desiredPushTypes = [PKPushType.voIP]
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
///....
}
func pushRegistry(_ registry: PKPushRegistry,
didReceiveIncomingPushWith payload: PKPushPayload,
for type: PKPushType
) {
processPush(with: payload.dictionaryPayload, and: nil)
}
func pushRegistry(_ registry: PKPushRegistry,
didReceiveIncomingPushWith payload: PKPushPayload,
for type: PKPushType,
completion: @escaping () -> Void
) {
processPush(with: payload.dictionaryPayload, and: completion)
}
private func processPush(with payload: Dictionary<AnyHashable, Any>,
and completion: (() -> Void)?
) {
// ....
}
Hi @tek08, in our case don't think it's a plugin conflict on UNUserNotificationCenter delegate since, as far as we can check, firebase_messaging is the only plugin requiring it. Other than this, strangely background notifications fetch is running quite smooth in DEBUG mode while we cannot get it to work in RELEASE mode. Anyway giving below our pubspec.yaml contents, hope this can help:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
cupertino_icons: ^1.0.2
shared_preferences: ^2.0.5
http: ^0.13.0
transparent_image: ^1.0.0
dart_numerics: ^0.0.5
quartet: ^0.1.1
flutter_staggered_grid_view: ^0.3.4
flutter_speed_dial: ^2.1.1
adaptive_action_sheet: ^2.0.0
path_provider: ^2.0.1
carousel_slider: ^3.0.0
photo_view: ^0.11.1
supercharged: ^2.0.0
simple_animations: ^3.0.3
video_player: ^2.0.2
flutter_svg: ^0.22.0
flutter_slidable: ^0.6.0
flutter_typeahead: ^3.1.2
intl: ^0.17.0
open_file: ^3.2.1
flutter_full_pdf_viewer: ^1.0.6
share: ^2.0.1
csv: ^5.0.0
badges: ^1.2.0
flutter_html: ^0.8.2
socket_io_client: ^1.0.1
device_info: ^2.0.0
email_validator: ^2.0.1
flutter_password_strength: ^0.1.6
image_picker: ^0.7.5+3
font_awesome_flutter: ^9.0.0
url_launcher: ^6.0.4
hive: ^2.0.4
hive_flutter: ^1.0.0
cached_network_image: ^3.0.0
uuid: ^3.0.4
connectivity: ^3.0.6
package_info_plus: ^1.0.3
firebase_core: ^1.6.0
firebase_messaging: ^10.0.6
sqflite: ^2.0.0+3
uni_links: ^0.5.1
launch_review: ^3.0.1
flutter_app_badger: ^1.2.0
flutter_ringtone_player: ^3.0.0
flutter_barcode_scanner: ^2.0.0
maps_launcher: ^2.0.1
rate_my_app: ^1.1.1
in_app_review: ^2.0.2
dev_dependencies:
flutter_test:
sdk: flutter
hive_generator: ^1.1.0
build_runner: ^2.0.4
flutter:
uses-material-design: true
dependency_overrides:
sqflite:
git:
url: https://github.com/TinyProgrammers/sqflite.git
path: sqflite
...
I have the same problem, i'm using flutter_local_notifications to show my notifications. In debug mode, everything works perfectly, but it doesn't work on release mode.
having the exact same issue and it is super annoying and not to mention it is a big release issue in order for our app to work on iOS. waiting for an update on this.
Hi all --
I'm just a friendly neighborhood developer. No relation to the Firebase nor Flutter teams. Apologies I can't troubleshoot each and every issue here (especially as with my limited dev time I'm working on figuring out my own issues with Push Notifications, still!), but happy to try to help when I have a spare minute. For the sake of everyone's sanity though, please, remember that this is open source software provided for free -- If your release is blocked by a flutter package, either get your hands dirty in the package's code to help figure out why, or write around it in Swift/Kotlin etc.
Re: release/debug differences on Android -- I've personally run into this a couple times as I moved dev environments. For me, it had to do with my app's Firebase configuration. @outailounni, sounds like this might up your alley. Make sure that your SHA-256 keys registered on console.firebase.com match the keys your app is using (there are separate keys for debug/release). Try this stack overflow answer for a hint in the right direction (using keytool etc to list your keys).
@angeloborrelli , flutter_app_badger
and I ran into problems in the past, but they don't sound similar to that which you're experiencing. Try the above, but also be aware that it looks like badger (much like awesome_notifications
as it is currently written) clobbers any custom iOS notification categories, which is where I was running into trouble, iirc.
@k3vinb0ss , I'm not familiar with PushKit
as I don't do watchOS dev. flutter_local_notifications
looks like it could interfere with presenting notifications. Check out line 700 here . If completionHandler
is not called somewhere with notification presentation options, notifications won't show. (Check out iOS docs here)
One somewhat gross way I've been debugging all push notification issues is to put in a method that sends a log statement to a local server on the network, and have been calling it when the various background delegate methods are running. It's not pretty, but has been helpful in diagnosing some ongoing issues. Maybe there is a better way ¯_(ツ)_/¯
I gave this another try today with the latest
firebase_core: ^1.6.0
firebase_messaging: ^10.0.6
and I was finally able to reproduce this issue as well.
Haven't changed anything about the sample I was running other than updating the plugin versions.
any news? we are getting huge troubles without this feature ........
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
The problem is that FirebaseMessaging notifications handlers work fine with Notification message
but don't work with Data message
. Is there any workaround to use older version of the plugin where handlers work with Data message
or this is an issue of using flutter_local_notifications
for displaying Data message
which delegates intervene with FirebaseMessaging ones??
Hi all, @paresy found a problem with iOS implementation here: https://github.com/FirebaseExtended/flutterfire/issues/4300#issuecomment-916883580
This might be related to this issue as well.
I have the same problem, i'm using flutter_local_notifications to show my notifications. In debug mode, everything works perfectly, but it doesn't work on release mode.
same problem, did you solve it
I have the same problem: iOS - background messages work as expected in debug build, do not work in the important release build. Any input / update highly appriciated. Also if anyone has an entry point, on how debug / dig deeper on this problem, I might find some time to try. And a lot of thanks to everyone contributed to this awesome OS project.
For me this example from the docs worked flawlessly: https://firebase.flutter.dev/docs/messaging/usage/#low-priority-messages
Before I implemented the configurations from the docs it only worked in debug mode.
Thanks Redhat, i had all the attributes from the article in the payload already but started playing around with it again. It seems to work now (most of the times). What I did change to be in line with doc is i put the token attribute also in the first position. Also I realized I have to turn on background refresh (hope that is the correct term in english) for the app. So it seems to work now. Thanks
For me this example from the docs worked flawlessly: https://firebase.flutter.dev/docs/messaging/usage/#low-priority-messages
Before I implemented the configurations from the docs it only worked in debug mode.
Isn't that just a data message, if you send a notification message with or without a data message, just wonder does it still works?
I added an notification property to the example I send and it worked too.
On iOS you have to add the parameters for a data message in order for the background handler to work.
I added an notification property to the example I send and it worked too.
On iOS you have to add the parameters for a data message in order for the background handler to work.
That’s not correct since messages must be fetched by background handler whether they have a data property or not.
See “Message types” and implementations to handle them here.
This is expected behavior/capability both on Android and iOS.
On our side, as already mentioned, we mixed in and tested every kind of message configuration (including official documented one, data only, notification only, data+notification, apns-push-type “background”, apns-push-type “alert”, with/without apns-priority “5-10”, attaching gcm.message_id
payload as suggested by @aytunch / @paresy and many others) but still on iOS we can make onMessage
and onBackgroundMessage
work only in debug mode.
I can only tell from my experience what worked from me. If you set the needed parameters for a data message (priority, topic, ...) you can add a notification property too.
Besides I wouldn't rely on the firebase documentation for flutter. In my experience it is contradicting (https://firebase.google.com/docs/cloud-messaging/concept-options#notification-messages-with-optional-data-payload) & sometimes misleading.
Same here.
Like others I tested many combinations too. And from what my iOS users reports, the backgroundhandler is not invoked. It works ok when app is in foreground of course. No big problems on android side (but not 100% delivery success of course).
I agree it's not easy to get started, to know which keys to use, there are the docs, stackoverflow and users experiences and their tips, examples in flutterfire docs using nodejs server and its api. It would probably be easier with simple postman/curl example to get a picture of what the payload really should be with the real json keys names.
@Ted-chiptech You can have both key "notification" and "data" in json, when using a local notiifcation package for example, but you'll get two notifications (the system notification is always shown in background, and the customized data notification). Data only are not garanteed to have best success rate delivery (cf docs), and using both keys in json, you can't hide the system notification. But that's another problem.
Hey, I faced the same problem and found a solution. When my Payload looks like this, my background handler gets invoked : `{ "to": "/topics/FvvNewApp", "notification": { "body" : "sample body", "OrganizationId":"2", "content_available" : true, "mutable_content": true, "priority" : "high", "subtitle":"sample sub-title", "Title":"hello", "click_action": "FLUTTER_NOTIFICATION_CLICK"}, "data" : { "msgBody" : "Body of your Notification", "msgTitle": "Title of your Notification", "msgId": "000001", "data" : "This is sample payloadData" }, "notification_priority" : "PRIORITY_MAX", "visibility" : "PUBLIC"
}` Maybe this helps someone facing the same problem. Tested on an iPhone 6s
In our case, we have been able to make onBackgroundMessage
work on iOS even if the app is terminated. However, this is not the case if the device is in low power mode / has low battery / is locked.
Our current workflow that works only when the device is NOT in low power mode is:
'apns-push-type': 'background', 'apns-priority': '5', contentAvailable: true
onBackgroundMessage
handler, since the app was awaken previously.If the device is in low power mode, the step 4 is not handled even when the app has been awaken. We know that the app has been awaken because when we click on the app icon, the splash screen is not loaded, and instead the home screen is already loaded.
However, if we send another notification AFTER the app has missed the previous notification+data message, this one is correctly handled by the onBackgroundMessage
. This is what is really strange to me. The handler probably gets awaken aswell when the first notification+data message arrives to the system notification center? Making the handler to work in next messages?
TLDR; If the iOS device is in low power mode and the app is still in terminated state, the onBackgroundMessage
is not called for the first notification+data message even when the app has been previously awaken by a data-only message. However, the second notification+data message will trigger the onBackgroundMessage
properly
Any news on this?, Another one here, onBackgroundMessage is not called in any way (app on background or terminated, knowing that it is normal on terminated), Android works really well.
I have to point out, that I actually receive the notification on the system tray (I'm sending data + notification), but the onBackgroundMessage is not called. onMessage works well on foreground
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
firebase_messaging: ^10.0.0
Flutter doctor
Run
flutter doctor
and paste the output below:Click To Expand
``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.0.3, on macOS 11.3 20E232 darwin-x64, locale en-AT) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 4.1) [✓] IntelliJ IDEA Ultimate Edition (version 2020.3.1) [✓] VS Code (version 1.56.2) [✓] Connected device (3 available) ```Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:Click To Expand
``` Dart SDK 2.12.2 Flutter SDK 2.0.3 dependencies: - firebase_analytics 8.1.0 [firebase_analytics_platform_interface firebase_analytics_web firebase_core flutter meta] - firebase_core 1.2.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 2.0.4 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_messaging 10.0.0 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] ... transitive dependencies: - firebase 9.0.1 [http http_parser js] - firebase_analytics_platform_interface 2.0.1 [flutter meta] - firebase_analytics_web 0.3.0+1 [firebase firebase_analytics_platform_interface flutter flutter_web_plugins meta] - firebase_core_platform_interface 4.0.1 [collection flutter meta plugin_platform_interface] - firebase_core_web 1.1.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.0.4 [collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 3.0.0 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 2.0.0 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] ... ```