I have been trying for few days now but I can't figure it out. The Firebase Messaging plugin just won't call the function that was set in onBackgroundMessage, not even when the application is in the background (and not terminated). I've tried this in debug and release builds, but nothing.
I'm trying to send the notifications via flutter_local_notifications but I don't think it matters as the callback doesn't even called.
I know for sure that my app is connected to Firebase because it does get notifications in onMessage.
The things I have done:
1) Connecting the app through the Firebase console, adding GoogleService-Info to the app.
2) Uploading to the Firebase console the APNs auth key.
3) Adding this function to my app as a top-level function:
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// Not called in background\terminated state
print("Handling a background message: ${message.messageId}");
...
}
and in the main():
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
4) Adding the following line to the AppDelegate:
import UIKit
import Flutter
import Firebase
import FirebaseMessaging
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
5) Making sure my app has push notifications and background modes enabled (in all builds):
6) Giving the app notifications permissions:

7) Sending the notification as follows (without the notification tag, only the data tag) using the node.js admin SDK:
let message = {
apns: {
headers: {
'apns-priority': '5',
},
payload: {
aps: {
contentAvailable: true
},
},
},
android: {
priority: 'normal',
},
data: {
title: "Test",
message: "Test",
url: "https://www.google.com/"
},
topic: topic
};
Debugging using the Console app on Mac brings the following result:
default 20:48:06.069282+0300 SpringBoard Received incoming message on topic com.matkonit at priority 5
default 20:48:06.082948+0300 SpringBoard [com.matkonit] Received remote notification request 3823-43DB [ waking: 0, hasAlertContent: 0, hasSound: 0 hasBadge: 0 hasContentAvailable: 1 hasMutableContent: 0 pushType: Background]
default 20:48:06.083005+0300 SpringBoard [com.matkonit] Process delivery of push notification 3823-43DB
So the notification does received by the OS and yet the Firebase handler is not called.
I have also tried countless solutions that were suggested on other StackOverlow posts but nothing helped...
Any help would be appreciated.

