Skip to content

[firebase_messaging]: iOS onBackgroundMessage not invoked in release mode (data-only/silent notifications), again #17982

@lukyanov

Description

@lukyanov

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 didReceiveRemoteNotification IS called and receives the full notification payload
  • Flutter's onBackgroundMessage handler is NEVER called

This proves the issue is in the FlutterFire bridging layer, not in Apple's notification delivery.

Reproducing the issue

  1. Create a Flutter app with firebase_messaging: 16.1.1
  2. Configure iOS for push notifications (APNs key, capabilities, etc.)
  3. 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());
}
  1. 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);
  1. Debug mode: Background handler IS invoked ✅
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked: customer-responseWaiting for customer response, e.g. more information was requested.platform: iosIssues / PRs which are specifically for iOS.plugin: messagingtype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions