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.68k stars 3.97k forks source link

[firebase_messaging] onBackgroundMessage is never called in a release mode on iOS when there are two apps under one Firebase account. #9534

Closed awaik closed 1 year ago

awaik commented 2 years ago

Bug report

This bug is connected with https://github.com/firebase/flutterfire/issues/9446

While for Android the bug is fixed by annotating background message handler with@pragma('vm:entry-point'), for iOS it doesn't fix it.

Steps to reproduce

  1. Use Flutter 3.3.1
  2. Build ipa file with flutter build ipa comand
  3. Upload it to the TestFlight
  4. App receives notifications if it is opened.
  5. If we dismiss the app (swipe up), onBackgroundMessage is not being called.

Flutter doctor

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.1, on macOS 11.6.7 20G630 darwin-x64, locale en-RU) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.71.0) [✓] Connected device (2 available) [✓] HTTP Host Availability • No issues found! ```

Flutter dependencies

Click To Expand ``` Dart SDK 2.18.0 Flutter SDK 3.3.1 agoradesk 1.0.13+37 dependencies: - auto_route 5.0.1 [flutter path collection meta] - auto_size_text 3.0.0 [flutter] - awesome_notifications 0.6.21 [flutter platform intl] - cached_network_image 3.2.1 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - collection 1.16.0 - connectivity_plus 2.3.0 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows] - country_picker 2.0.15 [flutter collection] - cupertino_icons 1.0.4 - currency_picker 2.0.11 [flutter collection] - decimal 2.2.0 [rational] - device_info_plus 4.1.2 [flutter device_info_plus_platform_interface device_info_plus_macos device_info_plus_linux device_info_plus_web device_info_plus_windows] - dio 4.0.6 [http_parser path] - dots_indicator 2.1.0 [flutter] - dropdown_search 5.0.2 [flutter] - duration 3.0.11 - easy_debounce 2.0.2+1 - event_bus 2.0.0 - expandable 5.0.1 [flutter] - extended_image 6.2.1 [extended_image_library flutter meta] - figma_squircle 0.5.3 [vector_math flutter] - firebase_core 1.22.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 13.0.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_displaymode 0.4.0 [flutter] - flutter_foreground_task 3.8.2 [flutter platform shared_preferences shared_preferences_android shared_preferences_ios] - flutter_inappwebview 5.4.3+7 [flutter] - flutter_keyboard_visibility 5.2.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter] - flutter_pin_code_widget 0.0.4+2 [flutter] - flutter_screenutil 5.5.3+2 [flutter] - flutter_secure_storage 5.0.2 [meta flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows] - flutter_svg 1.1.0 [flutter meta path_drawing vector_math xml] - flutter_verification_code 1.1.3 [flutter] - freezed_annotation 2.1.0 [collection json_annotation meta] - get_it 7.2.0 [async collection] - google_api_availability 3.0.1 [flutter meta] - image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface] - in_app_review 2.0.4 [flutter in_app_review_platform_interface] - insta_image_viewer 1.0.2 [flutter] - intl 0.17.0 [clock path] - json_annotation 4.5.0 [meta] - mapbox_search 3.0.1+2 [http] - markdown_widget 1.2.9 [flutter markdown highlight flutter_highlight html video_player_web video_player scrollable_positioned_list] - mobile_scanner 1.1.1 [flutter flutter_web_plugins js] - objectbox 1.6.2 [collection flat_buffers ffi meta path] - objectbox_flutter_libs 1.6.2 [objectbox path_provider] - overlay_support 2.0.1 [flutter async] - package_info_plus 1.4.3+1 [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.10 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - percent_indicator 4.2.2 [flutter] - permission_handler 10.0.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - plausible_analytics 0.1.4 [flutter universal_io] - pretty_dio_logger 1.2.0-beta-1 [dio] - provider 6.0.3 [collection flutter nested] - qr_flutter 4.0.0 [flutter qr] - rating_dialog 2.0.4 [flutter flutter_rating_bar] - rxdart 0.27.4 - sentry_flutter 6.9.1 [flutter flutter_web_plugins sentry package_info_plus meta] - share_plus 4.0.4 [meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web] - shimmer 2.0.0 [flutter] - sticky_headers 0.3.0+2 [flutter] - timeago 3.2.2 - uni_links 0.5.1 [flutter uni_links_platform_interface uni_links_web] - unifiedpush 4.0.0 [flutter shared_preferences unifiedpush_platform_interface unifiedpush_android] - url_launcher 6.1.2 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - visibility_detector 0.3.3 [flutter] - vm 1.0.3+1 [flutter provider] dev dependencies: - auto_route_generator 5.0.2 [build source_gen analyzer path build_runner code_builder dart_style xml args auto_route] - build_runner 2.1.11 [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 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] utter intl characters clock collection material_color_utilities meta path vector_math] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - freezed 2.1.0+1 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation] - json_serializable 6.2.0 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper] - mocktail 0.3.0 [collection matcher test] - objectbox_generator 1.6.2 [objectbox analyzer build collection dart_style glob path source_gen pubspec_parse yaml] dependency overrides: - flutter_foreground_task 3.8.2 [flutter platform shared_preferences shared_preferences_android shared_preferences_ios] transitive dependencies: - _fe_analyzer_shared 47.0.0 [meta] - analyzer 4.7.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - args 2.3.1 - async 2.9.0 [collection meta] - boolean_selector 2.1.0 [source_span string_scanner] - build 2.3.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.1.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.0.9 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.2.3 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.3.2 [built_collection collection fixnum meta] - 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.2.1 - charcode 1.3.1 - checked_yaml 2.0.1 [json_annotation source_span yaml] - clock 1.1.1 - code_builder 4.1.0 [built_collection built_value collection matcher meta] - connectivity_plus_linux 1.3.0 [flutter connectivity_plus_platform_interface meta nm] - connectivity_plus_macos 1.2.2 [connectivity_plus_platform_interface flutter] - connectivity_plus_platform_interface 1.2.0 [flutter meta plugin_platform_interface] - connectivity_plus_web 1.2.0 [connectivity_plus_platform_interface flutter_web_plugins flutter] - connectivity_plus_windows 1.2.0 [connectivity_plus_platform_interface flutter] - convert 3.0.2 [typed_data] - coverage 1.3.2 [args logging package_config path source_maps stack_trace vm_service] - cross_file 0.3.3+1 [js meta] - crypto 3.0.2 [typed_data] - csslib 0.17.2 [source_span] - dart_style 2.2.3 [analyzer args path pub_semver source_span] - dbus 0.7.7 [args ffi meta xml] - device_info_plus_linux 3.0.0 [device_info_plus_platform_interface file flutter meta] - device_info_plus_macos 3.0.0 [device_info_plus_platform_interface flutter] - device_info_plus_platform_interface 3.0.0 [flutter meta plugin_platform_interface] - device_info_plus_web 3.0.0 [device_info_plus_platform_interface flutter_web_plugins flutter] - device_info_plus_windows 4.0.0 [device_info_plus_platform_interface ffi flutter win32] - extended_image_library 3.3.0 [crypto flutter http_client_helper path path_provider] - fake_async 1.3.1 [clock collection] - ffi 2.0.1 - file 6.1.2 [meta path] - firebase_core_platform_interface 4.5.1 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 1.7.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 4.1.4 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.1.4 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - fixnum 1.0.1 - flat_buffers 2.0.5 - flutter_blurhash 0.7.0 [flutter] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_highlight 0.7.0 [flutter highlight] - 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_plugin_android_lifecycle 2.0.6 [flutter] - flutter_rating_bar 4.0.1 [flutter] - flutter_secure_storage_linux 1.1.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 1.1.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.0 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.0.2 [flutter flutter_web_plugins flutter_secure_storage_platform_interface js] - flutter_secure_storage_windows 1.1.2 [flutter flutter_secure_storage_platform_interface] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - frontend_server_client 2.1.3 [async path] - glob 2.0.2 [async collection file path string_scanner] - graphs 2.1.0 [collection] - highlight 0.7.0 [collection] - html 0.15.0 [csslib source_span] - http 0.13.4 [async http_parser meta path] - http_client_helper 2.0.2 [http] - http_multi_server 3.2.0 [async] - http_parser 4.0.1 [collection source_span string_scanner typed_data] - image_picker_android 0.8.4+13 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_for_web 2.1.8 [flutter flutter_web_plugins image_picker_platform_interface] - image_picker_ios 0.8.5+5 [flutter image_picker_platform_interface] - image_picker_platform_interface 2.5.0 [cross_file flutter http plugin_platform_interface] - in_app_review_platform_interface 2.0.3 [flutter url_launcher plugin_platform_interface platform] - io 1.0.3 [meta path string_scanner] - js 0.6.4 - lints 1.0.1 - logging 1.0.2 - markdown 5.0.0 [args charcode meta] - matcher 0.12.12 [stack_trace] - material_color_utilities 0.1.5 - meta 1.8.0 - mime 1.0.2 - nested 1.0.0 [flutter] - nm 0.5.0 [dbus] - node_preamble 2.0.1 - octo_image 1.0.2 [flutter flutter_blurhash] - package_config 2.0.2 [path] - package_info_plus_linux 1.0.5 [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.5 [flutter flutter_web_plugins http meta package_info_plus_platform_interface] - package_info_plus_windows 2.0.0 [package_info_plus_platform_interface ffi flutter win32] - path 1.8.2 - path_drawing 1.0.0 [vector_math meta path_parsing flutter] - path_parsing 1.0.0 [vector_math meta] - path_provider_android 2.0.14 [flutter path_provider_platform_interface] - path_provider_ios 2.0.9 [flutter path_provider_platform_interface] - path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.6 [flutter path_provider_platform_interface] - path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.2 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - permission_handler_android 10.0.0 [flutter permission_handler_platform_interface] - permission_handler_apple 9.0.4 [flutter permission_handler_platform_interface] - permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface] - permission_handler_windows 0.1.0 [flutter permission_handler_platform_interface] - petitparser 5.0.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.2 [meta] - pool 1.5.0 [async stack_trace] - process 4.2.4 [file path platform] - pub_semver 2.1.1 [collection meta] - pubspec_parse 1.2.0 [checked_yaml collection json_annotation pub_semver yaml] - qr 2.1.0 [meta] - rational 2.2.0 - scrollable_positioned_list 0.3.2 [flutter collection] - sentry 6.9.1 [http meta stack_trace uuid] - share_plus_linux 3.0.0 [share_plus_platform_interface file flutter meta url_launcher] - share_plus_macos 3.0.0 [share_plus_platform_interface flutter] - share_plus_platform_interface 3.0.2 [flutter meta mime plugin_platform_interface] - share_plus_web 3.0.0 [share_plus_platform_interface url_launcher flutter flutter_web_plugins meta] - share_plus_windows 3.0.0 [share_plus_platform_interface flutter meta url_launcher] - shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shared_preferences_android 2.0.12 [flutter shared_preferences_platform_interface] - shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.1.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface] - shared_preferences_platform_interface 2.0.0 [flutter] - shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.1.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - shelf 1.3.0 [async collection http_parser path stack_trace stream_channel] - shelf_packages_handler 3.0.0 [path shelf shelf_static] - shelf_static 1.1.0 [convert http_parser mime path shelf] - shelf_web_socket 1.0.1 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_gen 1.2.2 [analyzer async build dart_style glob meta path source_span yaml] - source_helper 1.3.2 [analyzer collection source_gen] - source_map_stack_trace 2.1.0 [path stack_trace source_maps] - source_maps 0.10.10 [source_span] - source_span 1.9.0 [collection path term_glyph] - sqflite 2.0.2+1 [flutter sqflite_common path] - sqflite_common 2.2.1+1 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.0 - string_scanner 1.1.1 [source_span] - synchronized 3.0.0+2 - term_glyph 1.2.1 - test 1.21.4 [analyzer async boolean_selector collection coverage http_multi_server io js node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel typed_data web_socket_channel webkit_inspection_protocol yaml test_api test_core] - test_api 0.4.12 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - test_core 0.4.16 [analyzer async args boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api] - timing 1.0.0 [json_annotation] - typed_data 1.3.1 [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] - unifiedpush_android 1.0.0 [flutter shared_preferences unifiedpush_platform_interface] - unifiedpush_platform_interface 1.0.0 [flutter plugin_platform_interface] - universal_io 2.0.4 [collection crypto meta typed_data] - url_launcher_android 6.0.17 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.0.5 [flutter plugin_platform_interface] - url_launcher_web 2.0.11 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface] - uuid 3.0.6 [crypto] - vector_math 2.1.2 - video_player 2.4.2 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web] - video_player_android 2.3.4 [flutter video_player_platform_interface] - video_player_avfoundation 2.3.4 [flutter video_player_platform_interface] - video_player_platform_interface 5.1.2 [flutter plugin_platform_interface] - video_player_web 2.0.10 [flutter flutter_web_plugins video_player_platform_interface] - vm_service 8.3.0 - watcher 1.0.1 [async path] - web_socket_channel 2.2.0 [async crypto stream_channel] - webkit_inspection_protocol 1.1.0 [logging] - win32 2.7.0 [ffi] - xdg_directories 0.2.0+1 [meta path process] - xml 6.1.0 [collection meta petitparser] - yaml 3.1.1 [collection source_span string_scanner] ```

darshankawar commented 2 years ago

@awaik Does the handler get called without uploading it on TestFlight ? ,ie, running app in --release mode locally ?

Also, can you take a look at this and see if it helps ?

awaik commented 2 years ago

Thank you! I'll check this https://github.com/firebase/flutterfire/issues/9381#issuecomment-1227415893 and come back.

awaik commented 2 years ago

@darshankawar

  1. Handler gets called with --debug mode.
  2. Handler gets called with --release mode.
  3. After uploading the app to the TestFlight notifications appears only if the app is in the foreground (so, the handler isn't called)
awaik commented 2 years ago

Ok, I think I got what's going on.

  1. I have two apps, under one Firebase account.
  2. Within this account I've made two Apple apps.

How the bug appears:

darshankawar commented 2 years ago

Thanks for further investigating. In this case, can you try by having a registration token that identifies each app instance so that you can use it to send notification that might trigger the background handler properly ? I am not sure how this should exactly work on iOS because if both apps are installed, one app would be in background and probably one is in foreground, so notification would not know whom to respond when background handler is called.

I suggest you to reach out to firebase support, because I don't think this will be actionable from client side, as, per your analysis, the background handler works properly if only one app is installed at a time.

awaik commented 2 years ago

I'm not quite sure, what do you mean by having a registration token that identifies each app instance.

The apps registered in the Firebase under different id's, they have different bundle names.

And under Android everything works as intended, with same two app under same Firebase account.

AND, most important, if we run two apps in the --debug mode - they are work as intended.

darshankawar commented 2 years ago

Thank you! I'll check this #9381 (comment) and come back.

Did you get a chance to check this ?

awaik commented 2 years ago

I'm sorry, forgot to mention, yes, we added this parameter to the payload.

darshankawar commented 2 years ago

Thanks for the update. I am keeping this issue open for team's insights on this case, ie: as described here https://github.com/firebase/flutterfire/issues/9534#issuecomment-1247905307

darshankawar commented 2 years ago

/cc @russellwheatley

hatemragab commented 2 years ago

i have good news it works in the native side there are bug with firebase_messageing package

9563

awaik commented 2 years ago

More details: 1st app - onBackgroundMessage called if the app dismissed 2nd app - onBackgroundMessage is never called

east-shine commented 1 year ago

How is this issue going? I can use @pragma('vm:entry-point') to get background notifications in android release mode, but in ios I can only receive background notifications in debug mode.

shrutika-tatkare-apptware commented 1 year ago

Hey, above is happening for me too

russellwheatley commented 1 year ago

Hey @awaik, you said:

If we dismiss the app (swipe up), onBackgroundMessage is not being called.

The background message handler will never be invoked if you dismiss the app. See documentation.

On iOS, if the user swipes away the application from the app switcher, it must be manually reopened for background messages to start working again.