Skip to content

[Firebase_messaging]: iOS regression (firebase_messaging >= 15.1.4) - onMessage not fired for subsequent foreground pushes with same apns-collapse-idĀ #17923

@vasa137

Description

@vasa137

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Messaging

Which platforms are affected?

iOS

Description

Summary

Since firebase_messaging 15.1.4 (PR #13572) we observed that on any iOS device the Flutter FirebaseMessaging.onMessage.listen callback can be suppressed when multiple foreground notifications reuse the same UNNotificationRequest.identifier (commonly when using apns-collapse-id to update/replace a notification).

Related issue: #17028
Likely regression introduced by: #13572
Changelog (15.1.4 includes #13572): https://pub.dev/packages/firebase_messaging/changelog#1514
Patch/diff: https://github.com/firebase/flutterfire/pull/13572.patch

Important note about reproducibility

  • Reproducible on any iOS version: we can reliably reproduce the issue (see steps below).
  • and the plugin currently performs a foreground ā€œduplicateā€ filter based on UNNotificationRequest.identifier, which is not safe when apns-collapse-id is used for legitimate updates.

Expected behavior

When the app is in the foreground, every incoming FCM message should trigger FirebaseMessaging.onMessage.listen,
even if multiple messages share the same apns-collapse-id (the OS can still collapse/replace the visible notification).

Actual behavior (any iOS device)

Only the first notification triggers onMessage. Subsequent notifications that reuse the same collapse ID / request identifier:

  • are delivered,
  • may appear/rewrite in Notification Center as expected,
  • but do not trigger FirebaseMessaging.onMessage.listen.

Suspected cause (regression from #13572)

PR #13572 introduced a foreground ā€œduplicate notificationā€ workaround for iOS 18 that:

  • reads notification.request.identifier,
  • skips invoking "Messaging#onMessage" when identifier == _foregroundUniqueIdentifier,
  • then sets _foregroundUniqueIdentifier = identifier.

When apns-collapse-id is used, iOS can map it to the UNNotificationRequest.identifier, so updates with the same collapse ID end up with the same identifier and get filtered out by the plugin.

Reproducing the issue

Repro steps

  1. Use firebase_messaging 15.1.4+ on iOS.
  2. Register a listener:
    FirebaseMessaging.onMessage.listen((msg) {
      debugPrint('onMessage: ${msg.messageId} data=${msg.data}');
    });
    

Firebase Core version

4.3.0

Flutter Version

3.32.8

Relevant Log Output

Flutter dependencies

Expand Flutter dependencies snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.

Additional context and comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions