-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Messaging
Which platforms are affected?
iOS
Description
FirebaseMessaging.onBackgroundMessage handler is never invoked on iOS in release builds for data-only (silent/content-available) notifications, even though the native iOS layer successfully receives the notification.
Key finding: By adding logging to both native iOS (AppDelegate.swift) and Flutter (onBackgroundMessage), I confirmed that:
- Native iOS
didReceiveRemoteNotificationIS called and receives the full notification payload - Flutter's
onBackgroundMessagehandler is NEVER called
This proves the issue is in the FlutterFire bridging layer, not in Apple's notification delivery.
Reproducing the issue
- Create a Flutter app with
firebase_messaging: 16.1.1 - Configure iOS for push notifications (APNs key, capabilities, etc.)
- Register a background message handler:
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
print('Background message received: ${message.data}');
// This never prints in release mode
}
void main() {
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(MyApp());
}- Send a data-only (silent) notification from Firebase Cloud Functions:
const message = {
token: fcmToken,
data: {
type: "my_update",
payload: "some data",
},
android: {
priority: "normal",
},
apns: {
headers: {
"apns-priority": "5",
},
payload: {
aps: {
contentAvailable: true,
},
},
},
};
await messaging.send(message);- Debug mode: Background handler IS invoked ✅
- Release mode: Background handler is NEVER invoked ❌
Expected behavior
onBackgroundMessage should be invoked when a data-only notification is received in release mode, just like it works in debug mode.
Actual behavior
The handler is never invoked in release builds. Native iOS receives the notification (confirmed via AppDelegate logging), but Flutter never gets it.
Firebase Core version
4.4.0
Flutter Version
3.38.7
Relevant Log Output
Flutter dependencies
No response
Additional context and comments
This workaround in AppDelegate.swift works:
override func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
// Handle the notification natively since Flutter's handler doesn't work
if let type = userInfo["type"] as? String, type == "my_update" {
// Process notification here
completionHandler(.newData)
return
}
super.application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
}P.S. Honestly, there are so many GitHub issues on the same subject and they are all closed either as "duplicates" or as "throttling on iOS level, we can't do anything about this". This is not throttling. I can see the notification coming every time I send them, but only in the native code (release and debug). It never gets to Flutter in release mode. In debug mode everything works including Flutter.