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.73k stars 3.98k forks source link

🐛 [Firebase_messaging] TOO_MANY_REGISTRATIONS when register device #10761

Closed khoale38 closed 1 year ago

khoale38 commented 1 year ago

Bug report

Describe the bug It saying : "FirebaseException [firebase_messaging/unknown] java.io.IOException: TOO_MANY_REGISTRATIONS"

Steps to reproduce

Steps to reproduce the behavior: This causes no fcmToken saved to my database => this could happen when registering fcmToken for the device

Expected behavior

fcmToken created and save to DB

Sample project

static Future<void> _registerDevice(NotificationSettings notification) async {
    String notificationStatus = 'declined';
    if (notification.authorizationStatus == AuthorizationStatus.authorized) {
      notificationStatus = 'authorized';
    } else if (notification.authorizationStatus ==
        AuthorizationStatus.provisional) {
      notificationStatus = 'provisional';
    } else {
      notificationStatus = 'declined';
    }
    String? fcmToken = await FirebaseMessaging.instance.getToken();

    PackageInfo packageInfo = await PackageInfo.fromPlatform();

    String? deviceId = await PlatformDeviceId.getDeviceId;

    final options = Options$Mutation$RegisterDevice(
      variables: Variables$Mutation$RegisterDevice(
        input: Input$RegisterDeviceInput(
            deviceId: deviceId ?? "unidentified-device-id",
            platform: Platform.operatingSystem,
            fcmToken: fcmToken ?? "",
            currentVersion: "${packageInfo.version}-${packageInfo.buildNumber}",
            notificationStatus: notificationStatus),
      ),
    );

    getShopClient()
        .mutate$RegisterDevice(options)
        .then(inspect)
        .catchError(onError);
  }
}

Additional context

Screen Shot 2023-04-11 at 11 07 12

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.7.6, on macOS 12.6 21G115 darwin-x64, locale en-VN) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [✓] VS Code (version 1.77.1) [✓] Connected device (3 available) ! Error: Mikaaa’s iPhone is busy: Fetching debug symbols for Mikaaa’s iPhone. Xcode will continue when Mikaaa’s iPhone is finished. (code -10) [✓] HTTP Host Availability • No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` dependencies: - app_tracking_transparency 2.0.3 [flutter] - appsflyer_sdk 6.9.3 [flutter] - badges 2.0.3 [flutter] - cached_network_image 3.2.3 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - carousel_slider 4.2.1 [flutter] - collection 1.17.0 - copy_with_extension 5.0.2 [meta] - cupertino_icons 1.0.5 - darq 1.2.1 - dart_jsonwebtoken 2.7.1 [crypto pointycastle convert collection ed25519_edwards] - decimal 2.3.2 [rational] - device_info_plus 8.1.0 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta win32] - dio 5.0.1 [http_parser meta path] - dotted_border 2.0.0+3 [flutter path_drawing] - enum_to_string 2.0.1 - envify 2.0.2 - equatable 2.0.5 [collection meta] - expandable_text 2.3.0 [flutter] - extended_text 10.0.0 [extended_text_library flutter] - fdottedline_nullsafety 2.0.1 [flutter] - firebase_core 2.7.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 14.2.5 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine] - flutter_form_builder 7.8.0 [flutter intl collection] - flutter_hooks 0.18.6 [flutter] - flutter_local_notifications 13.0.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math] - flutter_loggy 2.0.2 [flutter loggy rxdart] - flutter_native_splash 2.2.18 [args flutter flutter_web_plugins js html image meta path universal_io xml yaml] - flutter_secure_storage 8.0.0 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta] - flutter_svg 2.0.2 [flutter vector_graphics vector_graphics_codec vector_graphics_compiler] - flutter_switch 0.3.2 [flutter] - flutter_typeahead 4.3.7 [flutter flutter_keyboard_visibility] - flutter_use 0.0.3 [flutter flutter_hooks] - fluttertoast 8.1.1 [flutter flutter_web_plugins] - form_builder_validators 8.5.0 [flutter flutter_localizations intl] - freezed 2.2.0 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation] - freezed_annotation 2.2.0 [collection json_annotation meta] - from_css_color 2.0.0 [flutter] - geolocator 9.0.2 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows] - get_it 7.2.0 [async collection] - google_fonts 4.0.3 [flutter http path_provider crypto] - gql 0.14.0 [collection meta source_span] - graphql 5.1.3 [meta path gql gql_exec gql_link gql_http_link gql_transform_link gql_error_link gql_dedupe_link hive normalize http collection web_socket_channel stream_channel rxdart uuid] - graphql_flutter 5.1.2 [graphql gql_exec flutter meta path_provider path connectivity_plus hive plugin_platform_interface flutter_hooks] - hooks_riverpod 2.3.0 [collection flutter flutter_hooks flutter_riverpod riverpod state_notifier] - http 0.13.5 [async http_parser meta path] - intl 0.17.0 [clock path] - jiffy 5.0.0 [intl] - json_annotation 4.7.0 [meta] - loggy 2.0.3 [stack_trace] - meta 1.8.0 - nested_scroll_controller 1.0.0 [flutter] - package_info_plus 3.0.3 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - pinput 2.2.31 [flutter smart_auth universal_platform] - platform_device_id 1.0.1 [flutter platform_device_id_platform_interface platform_device_id_macos platform_device_id_linux platform_device_id_web platform_device_id_windows device_info] - provider 6.0.5 [collection flutter nested] - pull_to_refresh 2.0.0 [flutter] - sentry_flutter 6.21.0 [flutter flutter_web_plugins sentry package_info_plus meta] - sentry_link 0.1.2 [gql_error_link gql_exec gql_link gql sentry] - share_plus 6.3.1 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi win32] - skeleton_text 3.0.0 [flutter] - tab_indicator_styler 2.0.0 [flutter] - ui 0.0.1 [flutter google_fonts] - underline_indicator 0.0.4 [flutter] - uni_links 0.5.1 [flutter uni_links_platform_interface uni_links_web] - upgrader 6.0.1 [flutter device_info_plus html http os_detect package_info_plus shared_preferences url_launcher version xml] - url_launcher 6.1.10 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - uuid 3.0.7 [crypto] - visibility_detector 0.3.3 [flutter] dev dependencies: - build_runner 2.3.3 [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] - change_app_package_name 1.1.0 - copy_with_extension_gen 5.0.2 [analyzer build source_gen copy_with_extension meta] - envify_generator 2.0.2 [analyzer build dotenv envify path source_gen] - flutter_lints 2.0.1 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - graphql_codegen 0.12.0-beta.13 [gql build glob code_builder dart_style built_collection path gql_code_builder recase json_annotation] - json_serializable 6.5.4 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper] - widgetbook 2.4.1 [collection device_frame flutter freezed_annotation go_router provider widgetbook_models] transitive dependencies: - _fe_analyzer_shared 47.0.0 [meta] - _flutterfire_internals 1.0.16 [collection firebase_core firebase_core_platform_interface flutter meta] - adaptive_number 1.0.0 [fixnum] - analyzer 4.7.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - archive 3.3.6 [crypto path pointycastle] - args 2.4.0 - async 2.10.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - build 2.3.1 [analyzer async convert crypto glob logging meta path] - build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 3.1.1 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.0.10 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.2.7 [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.4.3 [built_collection collection fixnum meta] - cached_network_image_platform_interface 2.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.2 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.2.1 - checked_yaml 2.0.2 [json_annotation source_span yaml] - clock 1.1.1 - code_builder 4.4.0 [built_collection built_value collection matcher meta] - connectivity_plus 3.0.3 [flutter flutter_web_plugins connectivity_plus_platform_interface js meta nm] - connectivity_plus_platform_interface 1.2.4 [flutter meta plugin_platform_interface] - convert 3.1.1 [typed_data] - cross_file 0.3.3+4 [js meta] - crypto 3.0.2 [typed_data] - csslib 0.17.2 [source_span] - dart_style 2.2.4 [analyzer args path pub_semver source_span] - dbus 0.7.8 [args ffi meta xml] - device_frame 1.1.0 [freezed_annotation flutter] - device_info 2.0.3 [flutter device_info_platform_interface] - device_info_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - device_info_plus_platform_interface 7.0.0 [flutter meta plugin_platform_interface] - dotenv 4.1.0 [args meta] - ed25519_edwards 0.3.1 [collection crypto convert adaptive_number] - extended_text_library 9.1.1 [flutter] - fake_async 1.3.1 [clock collection] - ffi 2.0.1 - file 6.1.4 [meta path] - firebase_core_platform_interface 4.5.3 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.2.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 4.2.14 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.2.15 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - fixnum 1.1.0 - 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_keyboard_visibility 5.4.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_linux flutter_keyboard_visibility_macos flutter_keyboard_visibility_web flutter_keyboard_visibility_windows flutter] - flutter_keyboard_visibility_linux 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_keyboard_visibility_macos 1.0.0 [flutter_keyboard_visibility_platform_interface 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_keyboard_visibility_windows 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_local_notifications_linux 3.0.0+1 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories] - flutter_local_notifications_platform_interface 6.0.0 [flutter plugin_platform_interface] - flutter_riverpod 2.3.0 [collection flutter meta riverpod state_notifier] - flutter_secure_storage_linux 1.1.3 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 3.0.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.1 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.1.1 [flutter flutter_secure_storage_platform_interface flutter_web_plugins js] - flutter_secure_storage_windows 2.0.0 [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 3.2.0 [async path] - geolocator_android 4.1.7 [flutter geolocator_platform_interface] - geolocator_apple 2.2.5 [flutter geolocator_platform_interface] - geolocator_platform_interface 4.0.7 [flutter plugin_platform_interface vector_math meta] - geolocator_web 2.1.6 [flutter flutter_web_plugins geolocator_platform_interface] - geolocator_windows 0.1.1 [flutter geolocator_platform_interface] - glob 2.1.1 [async collection file path string_scanner] - go_router 3.1.1 [collection flutter flutter_web_plugins logging meta] - gql_code_builder 0.7.1 [analyzer built_collection built_value code_builder collection gql gql_exec path] - gql_dedupe_link 2.0.3+1 [async gql_exec gql_link meta] - gql_error_link 0.2.3+1 [async gql_exec gql_link meta] - gql_exec 0.4.3 [collection gql meta] - gql_http_link 0.4.5 [gql gql_exec gql_link http http_parser meta] - gql_link 0.5.1 [gql gql_exec meta] - gql_transform_link 0.2.2+1 [gql_exec gql_link] - graphs 2.2.0 [collection] - hive 2.2.3 [meta crypto] - html 0.15.1 [csslib source_span] - http_multi_server 3.2.1 [async] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.0.15 [archive meta xml] - io 1.0.4 [meta path string_scanner] - js 0.6.5 [meta] - lints 2.0.1 - logging 1.1.1 - matcher 0.12.13 [meta stack_trace] - material_color_utilities 0.2.0 - mime 1.0.4 - nested 1.0.0 [flutter] - nm 0.5.0 [dbus] - normalize 0.7.2 [gql collection] - octo_image 1.0.2 [flutter flutter_blurhash] - os_detect 2.0.1 - package_config 2.1.0 [path] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.2 - path_drawing 1.0.1 [vector_math meta path_parsing flutter] - path_parsing 1.0.1 [vector_math meta] - path_provider 2.0.13 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - path_provider_android 2.0.23 [flutter path_provider_platform_interface] - path_provider_foundation 2.1.2 [flutter path_provider_platform_interface] - path_provider_linux 2.1.9 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.0.6 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.4 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - petitparser 5.1.0 [meta] - platform 3.1.0 - platform_device_id_linux 1.0.0 [flutter] - platform_device_id_macos 1.0.0 [flutter] - platform_device_id_platform_interface 1.0.0 [flutter plugin_platform_interface] - platform_device_id_web 1.0.0 [flutter flutter_web_plugins platform_device_id_platform_interface] - platform_device_id_windows 1.0.0 [flutter] - plugin_platform_interface 2.1.4 [meta] - pointycastle 3.6.2 [collection convert js] - pool 1.5.1 [async stack_trace] - process 4.2.4 [file path platform] - pub_semver 2.1.3 [collection meta] - pubspec_parse 1.2.1 [checked_yaml collection json_annotation pub_semver yaml] - rational 2.2.2 - recase 4.1.0 - riverpod 2.3.0 [collection meta stack_trace state_notifier] - rxdart 0.27.7 - sentry 6.21.0 [http meta stack_trace uuid intl] - share_plus_platform_interface 3.2.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid] - shared_preferences 2.0.18 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shared_preferences_android 2.0.16 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.1.4 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.1.4 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.1.1 [flutter plugin_platform_interface] - shared_preferences_web 2.0.5 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.1.4 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - shelf 1.4.0 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 1.0.3 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - smart_auth 1.0.8 [flutter flutter_web_plugins] - source_gen 1.2.6 [analyzer async build dart_style glob meta path source_span yaml] - source_helper 1.3.3 [analyzer collection source_gen] - source_span 1.9.1 [collection path term_glyph] - sqflite 2.2.5 [flutter sqflite_common path] - sqflite_common 2.4.2+2 [synchronized path meta] - stack_trace 1.11.0 [path] - state_notifier 0.7.2+1 [meta] - stream_channel 2.1.1 [async] - stream_transform 2.1.0 - string_scanner 1.2.0 [source_span] - synchronized 3.0.1 - term_glyph 1.2.1 - test_api 0.4.16 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.9.1 [path] - timing 1.0.1 [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] - universal_io 2.2.0 [collection meta typed_data] - universal_platform 1.0.0+1 - url_launcher_android 6.0.24 [flutter url_launcher_platform_interface] - url_launcher_ios 6.1.1 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.3 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.3 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.2 [flutter plugin_platform_interface] - url_launcher_web 2.0.15 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.4 [flutter url_launcher_platform_interface] - vector_graphics 1.1.0 [flutter vector_graphics_codec] - vector_graphics_codec 1.1.0 - vector_graphics_compiler 1.1.0 [args meta path_parsing xml vector_graphics_codec] - vector_math 2.1.4 - version 3.0.2 - watcher 1.0.2 [async path] - web_socket_channel 2.2.0 [async crypto stream_channel] - widgetbook_models 0.0.7 [freezed_annotation meta] - win32 3.1.3 [ffi] - xdg_directories 0.2.0+3 [meta path process] - xml 6.2.2 [collection meta petitparser] - yaml 3.1.1 [collection source_span string_scanner] ```

darshankawar commented 1 year ago

@khoale38 [firebase_messaging/unknown] java.io.IOException: TOO_MANY_REGISTRATIONS" probably indicates your device is already registered or being reused many times.

Check this link and see if it helps in your case.

If above doesn't help, please provide a bare minimum but complete reproducible code sample without any third party package code implementation that triggers this exception, so that we can analyze it properly further.

khoale38 commented 1 year ago

I reviewed the post that you gave. Unfortunately, none of them would for this case. I just simply call

 static void registerPushNotification() async {
    //create instance to receive message from FCM
    FirebaseMessaging messaging = FirebaseMessaging.instance;

    //request for Permission
    final notificationSettings = await messaging.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      // this should be set to false as to get full granted permission

      sound: true,
    );

      _registerDevice(notificationSettings);

  }

in main file :

 void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  PushNotificationHandler.registerPushNotification();}
darshankawar commented 1 year ago

Thanks for the update. Are you using any third party package that might be conflicting ? I suggest you to try with barebone app with just firebase_messaging and other flutterfire required plugins such as firebase_core and then run your scenario again to see if you still get the same error or not.

Also try to use other device.

khoale38 commented 1 year ago

Since this bug does not appear very often. It is hard to reproduce this bug scenario. But it seems to me that it is likely not caused by any package conflict.

darshankawar commented 1 year ago

@khoale38 I don't think this is actionable from plugin side. You may want to reach out to firebase support and see what they say.

khoale38 commented 1 year ago

Reaching out to them.Thanks you for your support

avvari-da commented 1 year ago

@khoale38 Any update you got from firebase support?