firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.64k stars 3.96k forks source link

πŸ› [firebase_messaging] onMessageOpenedApp is not being triggered when clicking on notification in foreground/background #7372

Closed m-zaink closed 2 years ago

m-zaink commented 2 years ago

Bug report

onMessageOpenedApp callback is not being triggered when clicking on notifications (when app is in foreground or background) although onMessage callback does get triggered when on foreground.

Steps to reproduce

Steps to reproduce the behavior:

Sample Code

Flutter Version

Flutter 2.2.3 β€’ channel stable β€’ https://github.com/flutter/flutter.git
Framework β€’ revision f4abaa0735 (5 months ago) β€’ 2021-07-01 12:46:11 -0700
Engine β€’ revision 241c87ad80
Tools β€’ Dart 2.13.4

Firebase dependencies (+ other notifications dependencies)

flutter_local_notifications: ^9.1.1
firebase_core: ^1.10.0
firebase_messaging: ^11.1.0

Basic code replication

FirebaseMessaging.onMessage.listen(
  (RemoteMessage remoteMessage) {
      log('[FirebaseMessaging.onMessage] remoteMessage.notification: ${remoteMessage.notification}');
      log('[FirebaseMessaging.onMessage] remoteMessage.data: ${remoteMessage.data}');
      log('[FirebaseMessaging.onMessage] remoteMessage.messageId: ${remoteMessage.messageId}');
  },
);

FirebaseMessaging.onMessageOpenedApp.listen(
  (RemoteMessage remoteMessage) {
      log('[FirebaseMessaging.onMessageOpenedApp] remoteMessage.notification: ${remoteMessage.notification}');
      log('[FirebaseMessaging.onMessageOpenedApp] remoteMessage.data: ${remoteMessage.data}');
      log('[FirebaseMessaging.onMessageOpenedApp] remoteMessage.messageId: ${remoteMessage.messageId}');
  },
);

FirebaseMessaging.onBackgroundMessage(_onBackgroundMessage);

# Top level function
Future<void> _onBackgroundMessage(RemoteMessage remoteMessage) async {
  log('[_onBackgroundMessage] remoteNotification: ${remoteMessage.notification}');
  log('[_onBackgroundMessage] remoteNotification.contentAvailable: ${remoteMessage.contentAvailable}');
  log('[_onBackgroundMessage] remoteNotification.messageId: ${remoteMessage.messageId}');
}

Additional context


Flutter doctor

Click To Expand ``` [βœ“] Flutter (Channel stable, 2.2.3, on macOS 11.6 20G165 darwin-arm, locale en-IN) [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses [βœ“] Xcode - develop for iOS and macOS [βœ“] Chrome - develop for the web [!] Android Studio (version 2020.3) βœ— Unable to find bundled Java version. [βœ“] VS Code (version 1.62.2) [βœ“] Connected device (1 available) ! Error: Lee Cooper is not connected. Xcode will continue when Lee Cooper is connected. (code -13) ! Error: Sadiya's iPhone is not connected. Xcode will continue when Sadiya's iPhone is connected. (code -13) ! Error: Tony Stark is not connected. Xcode will continue when Tony Stark is connected. (code -13) ! Error: Sadiya Khan’s iPhone is not connected. Xcode will continue when Sadiya Khan’s iPhone is connected. (code -13) ! Doctor found issues in 2 categories. ```

Flutter dependencies

Click To Expand ``` Dart SDK 2.13.4 Flutter SDK 2.2.3 phoenix 1.0.0+1 dependencies: - auto_route 2.3.0 [flutter path collection] - carousel_slider 4.0.0 [flutter] - connectivity_plus 1.4.0 [flutter meta connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows] - cupertino_icons 1.0.3 - device_info_plus 2.2.0 [flutter device_info_plus_platform_interface device_info_plus_linux device_info_plus_macos device_info_plus_web device_info_plus_windows] - dio 4.0.1 [http_parser path] - equatable 2.0.3 [collection meta] - file_picker 3.0.4 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface] - firebase_core 1.10.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 11.1.0 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_downloader 1.7.1 [flutter] - flutter_local_notifications 9.0.2 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection meta path typed_data vector_math] - flutter_native_image 0.0.6+1 [flutter] - flutter_native_timezone 2.0.0 [flutter_web_plugins flutter js] - flutter_riverpod 0.14.0+3 [collection flutter meta riverpod state_notifier] - flutter_sound_lite 8.4.2 [path_provider recase uuid provider path synchronized logger flutter flutter_sound_platform_interface flutter_sound_web] - fluttertoast 8.0.8 [flutter flutter_web_plugins] - google_sign_in 5.1.0 [flutter google_sign_in_platform_interface google_sign_in_web meta] - image 3.0.8 [archive meta xml] - image_crop 0.4.0 [flutter] - intl 0.17.0 [clock path] - jiffy 4.1.0 [intl] - just_audio 0.9.15 [just_audio_platform_interface just_audio_web audio_session rxdart path path_provider async uuid crypto meta flutter] - lottie 1.2.1 [archive characters flutter path vector_math] - metadata_fetch 0.4.1 [http string_validator html] - mime 1.0.1 - mixpanel_flutter 1.3.1 [flutter] - moengage_flutter 4.1.0 [flutter] - month_picker_dialog 0.4.0 [flutter flutter_localizations intl rxdart] - noise_meter 3.0.3 [flutter audio_streamer] - objectbox 1.2.1 [collection ffi meta path] - objectbox_flutter_libs 1.2.1 [objectbox path_provider] - package_info_plus 1.3.0 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web] - path_provider 2.0.4 [flutter path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - permission_handler 8.1.6 [flutter meta permission_handler_platform_interface] - photo_manager 1.3.9+1 [flutter] - public_suffix 3.0.0 [punycode] - razorpay_flutter 1.2.7 [flutter eventify] - sentry_flutter 5.1.0 [flutter flutter_web_plugins sentry package_info_plus] - share_plus 2.2.0 [meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web] - shared_preferences 2.0.7 [flutter meta shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shimmer 2.0.0 [flutter] - sms_autofill 2.2.0 [pin_input_text_field flutter] - stream_chat_flutter 2.2.1 [cached_network_image characters chewie collection dio ezanimation file_picker flutter flutter_keyboard_visibility flutter_markdown flutter_portal flutter_slidable flutter_svg http_parser image_gallery_saver image_picker jiffy lottie meta path_provider photo_manager photo_view rxdart scrollable_positioned_list share_plus shimmer stream_chat_flutter_core substring_highlight synchronized url_launcher video_compress video_player video_thumbnail visibility_detector] - timeago 3.1.0 - uni_links 0.5.1 [flutter uni_links_platform_interface uni_links_web] - url_launcher 6.0.10 [flutter meta url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - video_player 2.2.3 [flutter meta video_player_platform_interface video_player_web] - video_thumbnail 0.3.3 [flutter] - visibility_detector 0.2.2 [flutter] - webview_flutter 2.0.13 [flutter] dev dependencies: - auto_route_generator 2.3.0 [build source_gen analyzer path build_runner code_builder dart_style auto_route] - build_runner 2.1.2 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - flutter_lints 1.0.4 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] - objectbox_generator 1.2.1 [objectbox analyzer build collection dart_style glob path source_gen pubspec_parse] dependency overrides: - chewie 1.2.2 [cupertino_icons flutter provider video_player wakelock] - country_code_picker 2.0.2 [flutter modal_bottom_sheet collection universal_platform] - meta 1.7.0 - rxdart 0.27.2 - tutorial_coach_mark 1.1.1 [flutter] transitive dependencies: - _fe_analyzer_shared 26.0.0 [meta] - analyzer 2.3.0 [_fe_analyzer_shared cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml pedantic] - archive 3.1.6 [crypto path] - args 2.3.0 - asn1lib 1.0.2 - async 2.6.1 [meta collection] - audio_session 0.1.6+1 [flutter flutter_web_plugins rxdart meta] - audio_streamer 2.0.3 [permission_handler flutter] - boolean_selector 2.1.0 [source_span string_scanner] - build 2.1.0 [analyzer async convert crypto glob logging meta path] - build_config 1.0.0 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 3.0.0 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.0.4 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.1.0 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.1.3 [built_collection collection fixnum meta] - cached_network_image 3.1.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.1.0 - charcode 1.2.0 - checked_yaml 2.0.1 [json_annotation source_span yaml] - cli_util 0.3.5 [meta path] - clock 1.1.0 - code_builder 4.1.0 [built_collection built_value collection matcher meta] - collection 1.15.0 - connectivity_plus_linux 1.1.0 [flutter connectivity_plus_platform_interface dbus meta nm] - connectivity_plus_macos 1.2.1 [connectivity_plus_platform_interface flutter] - connectivity_plus_platform_interface 1.1.0 [flutter meta plugin_platform_interface] - connectivity_plus_web 1.1.0+1 [connectivity_plus_platform_interface flutter_web_plugins flutter] - connectivity_plus_windows 1.2.0 [connectivity_plus_platform_interface flutter] - convert 3.0.1 [typed_data] - cross_file 0.3.2 [flutter js meta] - crypto 3.0.1 [collection typed_data] - crypto_keys 0.3.0 [pointycastle meta collection quiver] - csslib 0.17.1 [source_span] - dart_style 2.2.0 [analyzer args path pub_semver source_span] - dbus 0.5.6 [args ffi meta pedantic xml] - device_info_plus_linux 2.1.0 [device_info_plus_platform_interface file flutter meta] - device_info_plus_macos 2.2.0 [device_info_plus_platform_interface flutter] - device_info_plus_platform_interface 2.2.0 [flutter meta plugin_platform_interface] - device_info_plus_web 2.1.0 [device_info_plus_platform_interface flutter_web_plugins flutter] - device_info_plus_windows 2.1.0 [device_info_plus_platform_interface ffi flutter win32] - eventify 1.0.0 - ezanimation 0.5.0 [flutter] - fake_async 1.2.0 [clock collection] - ffi 1.1.2 - file 6.1.2 [meta path] - firebase_core_platform_interface 4.1.0 [collection flutter meta plugin_platform_interface] - firebase_core_web 1.2.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 3.0.9 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 2.1.0 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - fixnum 1.0.0 - flutter_blurhash 0.6.0 [flutter meta pedantic] - flutter_cache_manager 3.1.2 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_keyboard_visibility 5.1.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter] - flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface] - flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter] - flutter_local_notifications_linux 0.3.0 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories] - flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface] - flutter_markdown 0.6.8 [flutter markdown meta path] - flutter_plugin_android_lifecycle 2.0.4 [flutter] - flutter_portal 0.4.0 [flutter] - flutter_slidable 0.6.0 [flutter] - flutter_sound_platform_interface 8.4.2 [flutter meta plugin_platform_interface logger] - flutter_sound_web 8.4.2 [flutter_sound_platform_interface flutter logger flutter_web_plugins meta js] - flutter_svg 0.22.0 [flutter meta path_drawing vector_math xml] - flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math] - freezed_annotation 0.14.3 [collection json_annotation meta] - frontend_server_client 2.1.2 [async path] - glob 2.0.1 [async collection file path pedantic string_scanner] - google_sign_in_platform_interface 2.1.0 [flutter meta quiver] - google_sign_in_web 0.10.0+3 [flutter flutter_web_plugins google_sign_in_platform_interface js meta] - graphs 2.1.0 [collection] - html 0.15.0 [csslib source_span] - http 0.13.3 [async http_parser meta path pedantic] - http_multi_server 3.0.1 [async] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - image_gallery_saver 1.7.1 [flutter] - image_picker 0.8.4+1 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface] - image_picker_for_web 2.1.4 [flutter flutter_web_plugins image_picker_platform_interface meta] - image_picker_platform_interface 2.4.1 [flutter http meta plugin_platform_interface cross_file] - io 1.0.3 [meta path string_scanner] - jose 0.3.2 [crypto_keys meta typed_data x509 http http_parser asn1lib collection] - js 0.6.3 - json_annotation 4.1.0 [meta] - just_audio_platform_interface 4.0.0 [flutter plugin_platform_interface] - just_audio_web 0.4.2 [just_audio_platform_interface flutter flutter_web_plugins] - lints 1.0.1 - logger 1.1.0 - logging 1.0.2 - markdown 4.0.0 [args charcode meta] - matcher 0.12.10 [stack_trace] - modal_bottom_sheet 2.0.0 [flutter] - nested 1.0.0 [flutter] - nm 0.3.0 [dbus] - octo_image 1.0.0+1 [flutter flutter_blurhash] - package_config 2.0.2 [path] - package_info_plus_linux 1.0.3 [package_info_plus_platform_interface flutter path] - package_info_plus_macos 1.3.0 [flutter] - package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface] - package_info_plus_web 1.0.4 [flutter flutter_web_plugins http meta package_info_plus_platform_interface] - package_info_plus_windows 1.0.4 [package_info_plus_platform_interface ffi flutter win32] - path 1.8.0 - path_drawing 0.5.1+1 [vector_math meta path_parsing flutter] - path_parsing 0.2.1 [vector_math meta] - path_provider_linux 2.1.0 [flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.2 [flutter] - path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface] - path_provider_windows 2.0.3 [ffi flutter meta path path_provider_platform_interface win32] - pedantic 1.11.1 - permission_handler_platform_interface 3.6.1 [flutter meta plugin_platform_interface] - petitparser 4.2.0 [meta] - photo_view 0.12.0 [flutter] - pin_input_text_field 4.1.1 [flutter] - platform 3.0.2 - plugin_platform_interface 2.0.2 [meta] - pointycastle 3.3.5 [collection convert js] - pool 1.5.0 [async stack_trace] - process 4.2.3 [file path platform] - provider 6.0.1 [collection flutter nested] - pub_semver 2.1.0 [collection meta] - pubspec_parse 1.1.0 [checked_yaml collection json_annotation pub_semver yaml] - punycode 1.0.0 - quiver 3.0.1+1 [matcher] - rate_limiter 0.1.1 - recase 4.0.0 - riverpod 0.14.0+3 [collection freezed_annotation meta state_notifier] - scrollable_positioned_list 0.2.2 [flutter collection] - sentry 5.1.0 [http meta stack_trace uuid] - share_plus_linux 2.0.4 [share_plus_platform_interface file flutter meta url_launcher] - share_plus_macos 2.0.2 [share_plus_platform_interface flutter] - share_plus_platform_interface 2.0.1 [flutter meta mime plugin_platform_interface] - share_plus_web 2.0.4 [share_plus_platform_interface url_launcher flutter flutter_web_plugins meta] - share_plus_windows 2.0.3 [share_plus_platform_interface flutter meta url_launcher] - shared_preferences_linux 2.0.2 [file meta flutter path path_provider_linux shared_preferences_platform_interface] - shared_preferences_macos 2.0.2 [flutter shared_preferences_platform_interface] - shared_preferences_platform_interface 2.0.0 [flutter] - shared_preferences_web 2.0.2 [flutter flutter_web_plugins meta shared_preferences_platform_interface] - shared_preferences_windows 2.0.2 [flutter file meta path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - shelf 1.2.0 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 1.0.1 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_gen 1.1.1 [analyzer async build dart_style glob meta path source_span yaml] - source_span 1.8.1 [collection path term_glyph] - sqflite 2.0.0+4 [flutter sqflite_common path] - sqflite_common 2.0.1+1 [synchronized path meta] - stack_trace 1.10.0 [path] - state_notifier 0.7.1 [meta] - stream_channel 2.1.0 [async] - stream_chat 2.2.1 [async collection dio equatable freezed_annotation http_parser jose json_annotation logging meta mime rate_limiter rxdart uuid web_socket_channel] - stream_chat_flutter_core 2.2.1 [collection connectivity_plus flutter meta rxdart stream_chat] - stream_transform 2.0.0 - string_scanner 1.1.0 [charcode source_span] - string_validator 0.3.0 - substring_highlight 1.0.33 [flutter] - synchronized 3.0.0 - term_glyph 1.2.0 - test_api 0.3.0 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.8.0 [path] - timing 1.0.0 [json_annotation] - typed_data 1.3.0 [collection] - uni_links_platform_interface 1.0.0 [flutter plugin_platform_interface] - uni_links_web 0.1.0 [flutter flutter_web_plugins uni_links_platform_interface] - universal_platform 1.0.0+1 - url_launcher_linux 2.0.2 [flutter] - url_launcher_macos 2.0.2 [flutter] - url_launcher_platform_interface 2.0.4 [flutter plugin_platform_interface] - url_launcher_web 2.0.4 [flutter flutter_web_plugins meta url_launcher_platform_interface] - url_launcher_windows 2.0.2 [flutter] - uuid 3.0.5 [crypto] - vector_math 2.1.0 - video_compress 3.1.0 [flutter] - video_player_platform_interface 4.2.0 [flutter flutter_test meta] - video_player_web 2.0.4 [flutter flutter_web_plugins meta video_player_platform_interface] - wakelock 0.5.6 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web wakelock_windows] - wakelock_macos 0.4.0 [flutter flutter_web_plugins wakelock_platform_interface] - wakelock_platform_interface 0.3.0 [flutter meta] - wakelock_web 0.4.0 [flutter flutter_web_plugins js wakelock_platform_interface] - wakelock_windows 0.2.0 [flutter wakelock_platform_interface win32] - watcher 1.0.0 [async path pedantic] - web_socket_channel 2.1.0 [async crypto stream_channel] - win32 2.2.10 [ffi] - x509 0.2.2 [asn1lib quiver crypto_keys] - xdg_directories 0.2.0 [meta path process] - xml 5.2.0 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```

darshankawar commented 2 years ago
Flutter 2.2.3

@m-zaink Can you upgrade to latest stable and try again to see if it works ? Also, can you also make use of getInitialMessage() https://pub.dev/documentation/firebase_messaging/latest/firebase_messaging/FirebaseMessaging/getInitialMessage.html and see if it helps ?

google-oss-bot commented 2 years ago

Hey @m-zaink. 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!

yassinsameh commented 2 years ago

Issue still persists with the latest flutter version 2.5.3 , Firebase Messaging 11.1.0, Awesome Notifications 0.6.18+2. @darshankawar

Same code, previously working, after updating both awesome notifications and Firebase Messaging the conflict seems to occur.

yassinsameh commented 2 years ago

@darshankawar @daikini What info can i provide to help solve and debug this issue? The issues is only with IOS, android works as expected. Thanks.

google-oss-bot commented 2 years ago

Hey @m-zaink. 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 commented 2 years ago

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

@m-zaink 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.