flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[FIREBASE MESSAGING]: If the UNNotificationRequest identifier is the same as the previously received identifier, onMessage won't trigger

Open flaviodsilverio opened this issue 1 year ago β€’ 12 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues.

Which plugins are affected?

Messaging

Which platforms are affected?

iOS

Description

If you receive several push notifications in a row with the same identifier while having the app on the foreground, only the first one triggers .onMessage.listen. However if you receive several in a row, but with different identifiers, they work perfectly.

ie.: "1" > "1" > "1"

only the first one shows up, even if all 3 trigger

        _ center: UNUserNotificationCenter,
        willPresent notification: UNNotification,
        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
    ) {
        print("willPresent notification")
        //notification.request.identifier = Int.random(in: 0..<6000).description
        
            completionHandler([])
    }```

"1" > "2" > "1" > "2"

They all trigger as expected


### Reproducing the issue

I've tried with a couple different projects and always happens. With, or without, native iOS code on the AppDelegate to intercept the notifications before Flutter. 

### Firebase Core version

3.11.0

### Flutter Version

3.29.3

### Relevant Log Output

```shell
[βœ“] Flutter (Channel stable, 3.29.3, on macOS 15.3.2 24D81 darwin-arm64, locale en-GB)
[βœ“] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[βœ“] Xcode - develop for iOS and macOS (Xcode 16.4)
[βœ“] Chrome - develop for the web
[βœ“] Android Studio (version 2024.3)
[βœ“] VS Code (version 1.101.2)
[βœ“] Connected device (4 available)
[βœ“] Network resources

β€’ No issues found!

Flutter dependencies

Expand Flutter dependencies snippet

- _flutterfire_internals 1.3.57 [collection firebase_core firebase_core_platform_interface flutter meta]
- ansicolor 2.0.3
- app_links_linux 1.0.3 [flutter app_links_platform_interface gtk]
- app_links_platform_interface 2.0.2 [flutter plugin_platform_interface]
- app_links_web 1.0.4 [flutter flutter_web_plugins app_links_platform_interface web]
- archive 4.0.7 [crypto path posix]
- args 2.7.0
- async 2.12.0 [collection meta]
- boolean_selector 2.1.2 [source_span string_scanner]
- cached_network_image_platform_interface 4.1.1 [flutter flutter_cache_manager]
- cached_network_image_web 1.3.1 [cached_network_image_platform_interface flutter flutter_cache_manager web]
- characters 1.4.0
- checked_yaml 2.0.3 [json_annotation source_span yaml]
- cli_util 0.4.2 [meta path]
- clock 1.1.2
- cross_file 0.3.4+2 [meta web]
- crypto 3.0.6 [typed_data]
- csslib 1.0.2 [source_span]
- dbus 0.7.11 [args ffi meta xml]
- device_info_plus_platform_interface 7.0.3 [flutter meta plugin_platform_interface]
- equatable 2.0.7 [collection meta]
- fake_async 1.3.2 [clock collection]
- ffi 2.1.4
- file 7.0.1 [meta path]
- file_selector_linux 0.9.3+2 [cross_file file_selector_platform_interface flutter]
- file_selector_macos 0.9.4+3 [cross_file file_selector_platform_interface flutter]
- file_selector_platform_interface 2.6.2 [cross_file flutter http plugin_platform_interface]
- file_selector_windows 0.9.3+4 [cross_file file_selector_platform_interface flutter]
- firebase_analytics_platform_interface 4.4.1 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.5.10+14 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins]
- firebase_app_check_platform_interface 0.1.1+8 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_app_check_web 0.2.0+12 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins web]
- firebase_core_platform_interface 5.4.1 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.24.0 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_crashlytics_platform_interface 3.8.8 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_in_app_messaging_platform_interface 0.2.5+8 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 4.6.8 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.10.8 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins meta web]
- firebase_performance_platform_interface 0.1.5+8 [_flutterfire_internals firebase_core flutter plugin_platform_interface]
- firebase_performance_web 0.1.7+14 [_flutterfire_internals firebase_core firebase_core_web firebase_performance_platform_interface flutter flutter_web_plugins]
- firebase_remote_config_platform_interface 1.5.6 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_remote_config_web 1.8.6 [_flutterfire_internals firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins]
- fixnum 1.1.1
- flutter_inappwebview 6.1.5 [flutter flutter_inappwebview_platform_interface flutter_inappwebview_android flutter_inappwebview_ios flutter_inappwebview_macos flutter_inappwebview_web flutter_inappwebview_windows]
- flutter_inappwebview_android 1.1.3 [flutter flutter_inappwebview_platform_interface]
- flutter_inappwebview_internal_annotations 1.2.0
- flutter_inappwebview_ios 1.1.2 [flutter flutter_inappwebview_platform_interface]
- flutter_inappwebview_macos 1.1.2 [flutter flutter_inappwebview_platform_interface]
- flutter_inappwebview_platform_interface 1.3.0+1 [flutter flutter_inappwebview_internal_annotations plugin_platform_interface]
- flutter_inappwebview_web 1.1.2 [flutter flutter_web_plugins web flutter_inappwebview_platform_interface]
- flutter_inappwebview_windows 0.6.0 [flutter flutter_inappwebview_platform_interface]
- flutter_local_notifications_linux 5.0.0 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories]
- flutter_local_notifications_platform_interface 8.0.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.28 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- google_identity_services_web 0.3.3+1 [meta web]
- google_sign_in_android 6.2.1 [flutter google_sign_in_platform_interface]
- google_sign_in_ios 5.9.0 [flutter google_sign_in_platform_interface]
- google_sign_in_platform_interface 2.5.0 [flutter plugin_platform_interface]
- google_sign_in_web 0.12.4+4 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http web]
- gtk 2.1.0 [ffi flutter meta]
- html 0.15.6 [csslib source_span]
- image_picker_android 0.8.12+23 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 3.0.6 [flutter flutter_web_plugins image_picker_platform_interface mime web]
- image_picker_ios 0.8.12+2 [flutter image_picker_platform_interface]
- image_picker_linux 0.2.1+2 [file_selector_linux file_selector_platform_interface flutter image_picker_platform_interface]
- image_picker_macos 0.2.1+2 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface]
- image_picker_platform_interface 2.10.1 [cross_file flutter http plugin_platform_interface]
- image_picker_windows 0.2.1+1 [file_selector_platform_interface file_selector_windows flutter image_picker_platform_interface]
- in_app_review_platform_interface 2.0.5 [flutter url_launcher plugin_platform_interface platform]
- json_annotation 4.9.0 [meta]
- leak_tracker 10.0.8 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.9 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- lints 5.1.1
- logger 2.6.0
- matcher 0.12.17 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.11.1 [collection]
- meta 1.16.0
- mime 2.0.0
- octo_image 2.1.0 [flutter]
- package_info_plus_platform_interface 3.2.0 [flutter meta plugin_platform_interface]
- path_provider_android 2.2.17 [flutter path_provider_platform_interface]
- path_provider_foundation 2.4.1 [flutter path_provider_platform_interface]
- path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface]
- path_provider_windows 2.3.0 [ffi flutter path path_provider_platform_interface]
- permission_handler_android 12.1.0 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.4.7 [flutter permission_handler_platform_interface]
- permission_handler_html 0.1.3+5 [flutter flutter_web_plugins permission_handler_platform_interface web]
- permission_handler_platform_interface 4.3.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.2.1 [flutter permission_handler_platform_interface]
- petitparser 6.1.0 [meta collection]
- platform 3.1.6
- plugin_platform_interface 2.1.8 [meta]
- posix 6.0.3 [ffi meta path]
- riverpod 2.6.1 [collection meta stack_trace state_notifier]
- rxdart 0.28.0
- share_plus_platform_interface 5.0.2 [cross_file flutter meta mime plugin_platform_interface path_provider uuid]
- shared_preferences_foundation 2.5.4 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.4.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.4.1 [flutter plugin_platform_interface]
- shared_preferences_web 2.4.3 [flutter flutter_web_plugins shared_preferences_platform_interface web]
- shared_preferences_windows 2.4.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sign_in_with_apple_platform_interface 1.1.0 [flutter plugin_platform_interface meta]
- sign_in_with_apple_web 2.1.1 [flutter flutter_web_plugins sign_in_with_apple_platform_interface]
- sky_engine 0.0.0
- source_span 1.10.1 [collection path term_glyph]
- sqflite_android 2.4.1 [flutter sqflite_common path sqflite_platform_interface]
- sqflite_common 2.5.5 [synchronized path meta]
- sqflite_darwin 2.4.2 [flutter sqflite_platform_interface meta sqflite_common path]
- sqflite_platform_interface 2.4.0 [flutter platform sqflite_common plugin_platform_interface meta]
- stack_trace 1.12.1 [path]
- state_notifier 1.0.0 [meta]
- stream_channel 2.1.4 [async]
- string_scanner 1.4.1 [source_span]
- synchronized 3.3.1
- term_glyph 1.2.2
- test_api 0.7.4 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- timezone 0.10.1 [http path]
- typed_data 1.4.0 [collection]
- universal_io 2.2.2 [collection meta typed_data]
- url_launcher_android 6.3.16 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.3.3 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.2.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.2.2 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface]
- url_launcher_web 2.4.1 [flutter flutter_web_plugins url_launcher_platform_interface web]
- url_launcher_windows 3.1.4 [flutter url_launcher_platform_interface]
- uuid 4.5.1 [crypto sprintf meta fixnum]
- vector_math 2.1.4
- vm_service 14.3.1
- web 1.0.0
- webview_flutter_android 4.7.0 [flutter meta webview_flutter_platform_interface]
- webview_flutter_platform_interface 2.13.1 [flutter meta plugin_platform_interface]
- webview_flutter_wkwebview 3.22.0 [flutter meta path webview_flutter_platform_interface]
- win32 5.13.0 [ffi]
- win32_registry 1.1.5 [ffi win32]
- xdg_directories 1.1.0 [meta path]
- xml 6.5.0 [collection meta petitparser]
- yaml 3.1.3 [collection source_span string_scanner]

Additional context and comments

No response

flaviodsilverio avatar Jul 03 '25 14:07 flaviodsilverio

Hi @flaviodsilverio, could you share the exact steps you're using to reproduce this issue? Specifically:

  • Are you explicitly setting an identifier when sending the notifications?
  • If so, how are you setting it?

SelaseKay avatar Jul 03 '25 16:07 SelaseKay

Hey @SelaseKay, we're sending it to Firebase on the apns header, as per the docs, ie.:

                    'apns' => [
                        'headers' => [
                            'apns-collapse-id' => "identifier" ,
                        ]

This then gets received by the app as the identifier of the UNNotification request.

flaviodsilverio avatar Jul 04 '25 09:07 flaviodsilverio

Hi if you are using apns-collapse-id, what you are experiencing appears to be intended behaviour: https://developer.apple.com/documentation/usernotifications/sending-notification-requests-to-apns


apns-collapse-id |
 Optional |
 An identifier you use to merge multiple notifications into a single notification for the user. Typically, each notification request displays a new notification on the user’s device. When sending the same notification more than once, use the same value in this header to merge the requests. The value of this key must not exceed 64 bytes.


If you want a unique identifier for your message use apns-id instead.

MichaelVerdon avatar Jul 04 '25 10:07 MichaelVerdon

Hello @MichaelVerdon, maybe it was my fault for not being clear enough, but replacing isn't an issue at all, that's the intended behaviour. The issue lies in the triggering of the onMessage.listen from FirebaseMessaging in Flutter with the app on the Foreground, specifically. Let me explain it better, and I'll give you examples of what is happening and what should happen:

So let's say you have an app that can receive 3 types of notifications: "log", "warning", and "error", and you'd like to only, ever, have the latest of each. For this, specifically, you're going to use their type as the 'apns-collapse-id'.

If you're using the app, and so if is in Foreground, the native iOS method that will be triggered is:

func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
)

this triggers perfectly, in every single received notification with the app on the foreground.

Now, the Flutter equivalent with FirebaseMessaging, that triggers and lets your app know that you received a notification on the Foreground is onMesssage.listen, as you can see in the docs: https://firebase.google.com/docs/cloud-messaging/flutter/receive

There lies the issue, due to it ignoring any that arrive and arrie after one with the same apns-collapse-id. This must not be intended since apps need to know what did arrive.

So, right now, if a user has gotten 10 notifications in the following order:

log -> 'warning' -> 'error' -> log -> 'warning' -> 'error' -> log -> 'warning' -> 'error' -> 'log'

both the system's willPresent notification and onMesssage.listen would trigger, and inform the app of the notification arrival, 10 times. However if the 10 notifications were:

log -> 'log' -> 'warning' -> 'error' -> log -> 'log' -> 'warning' -> 'error' -> log -> 'warning'

While the system's willPresent notification would trigger, as expected, the 10 times, onMesssage.listen would only trigger 8, since the two log that are after a previous log are currently being ignored and won't trigger the appropriate method response.

Let me know if this helped clearing things out.

flaviodsilverio avatar Jul 07 '25 11:07 flaviodsilverio

Hi @flaviodsilverio, thanks for the additional details. It was very helpful. I've been able to reproduce this issue and I believe I know the cause. There was a bug on iOS 18 which resulted in duplicate foreground notifications. As a result, we added a check as a workaround fix: FLTFirebaseMessagingPlugin.m#L330. Removing this check should resolve the issue. However, I'm not sure if the underlying bug on iOS 18 has been fixed.

SelaseKay avatar Jul 09 '25 09:07 SelaseKay

@SelaseKay, I do believe that iOS 18 bug was fixed, since I do use foreground notifications very often and it does not seem to occur.

flaviodsilverio avatar Jul 16 '25 09:07 flaviodsilverio

Would you say the issue is now resolved @flaviodsilverio ?

MichaelVerdon avatar Jul 24 '25 11:07 MichaelVerdon

Hey @flaviodsilverio. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Aug 04 '25 18:08 google-oss-bot

@MichaelVerdon, no I would not say that, since it is not yet resolved.

flaviodsilverio avatar Aug 13 '25 09:08 flaviodsilverio

@MichaelVerdon, no I would not say that, since it is not yet resolved.

Hi there, my bad I was under the impression you ran a local patch with the change suggested by @SelaseKay, could you try run a local patch of FlutterFire doing that and tell me if it resolves it for you?

MichaelVerdon avatar Aug 21 '25 06:08 MichaelVerdon

Hey @flaviodsilverio. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Sep 01 '25 18:09 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@flaviodsilverio if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Sep 09 '25 18:09 google-oss-bot