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] Error when subscribing to topics: "Invalid registration response :'Error=INVALID_PARAMETERS'. It is missing 'token' field." #9874

Closed downhamd closed 1 year ago

downhamd commented 1 year ago

Bug report

Describe the bug

I am getting the following error when I try to subscribe to topics:

FLTFirebaseMessaging: An error occurred while calling method Messaging#subscribeToTopic, errorOrNil => {
    NSLocalizedFailureReason = "Invalid registration response :'Error=INVALID_PARAMETERS'. It is missing 'token' field.";
}
flutter: subscription error: [firebase_messaging/unknown] An unknown error has occurred.

Here is my function which is meant to obtain permissions for push notifications, then gets the token and subscribes to a list of topics...

  Future<void> requestMessagingPermission() async {
    FirebaseMessaging messaging = FirebaseMessaging.instance;

    NotificationSettings settings = await messaging.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      sound: true,
    );

    print('User granted permission: ${settings.authorizationStatus}');

    if (settings.authorizationStatus == AuthorizationStatus.authorized) {
      print('User granted notifiactions permission');

      messaging.getToken().then((token) async {
        print('Messaging token: $token');

        //configure notification topics
        //gets a list of strings (topic names) from provider and loops through them to subscribe to them all

        GlobalProvider provider = context.read<GlobalProvider>();
        if (provider.notificationTopicsSet == false) {

          //subscribe to topics
          for (var topic in provider.notificationTopics) {
            print('topic subscribing... $topic');

            try {
              await messaging.subscribeToTopic(topic).then((value) => print('topic subscribed: $topic'));
            } catch (e) {
              print('subscription error: $e');
            }
          }

        }
      });

    }
  }

I am getting the same error in the console for every topic that is being looped through and subscribed to. The weird thing is that push notifications were working before, but now they don't seem to be.

I have tried updating Flutter to the latest version (3.3.7), I have tried updating both the Firebase Core package (2.1.1) and the Firebase messaging package to their latest versions (14.0.4) and I am still getting the error.

What is this token that is missing? The subscribeToTopic() function only seems to take the topic name string. Am I missing something?

I have looked around for answers and haven't found much, some say that it may be to do with an xCode update, that is a possibility I suppose. Some have said that it may be to do with leaving a small amount of time like 1 second between getting the token and subscribing to topics. Is there anything that could be pointing to those?

Similar and possibly related to this or this?

Thank you very much, any help will be greatly appreciated.

Steps to reproduce

Steps to reproduce the behavior:

  1. Add the firebase_messaging plugin to your flutter project
  2. Copy the above code in order to initialize the messaging plugin

Expected behavior

I expect to be able to loop through a list of topic names and be able to subscribe to each topic.

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.3.7, on macOS 13.0 22A380 darwin-arm, locale en-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS (Xcode 14.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.1) [✓] VS Code (version 1.73.0) [✓] Connected device (3 available) [✓] HTTP Host Availability • No issues found! ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 2.18.4 Flutter SDK 3.3.7 dependencies: - auto_orientation 2.2.1 [flutter] - cached_network_image 3.2.1 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - cupertino_icons 1.0.4 - firebase_core 2.1.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 14.0.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flash 2.0.3+2 [flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_inappwebview 5.4.3+7 [flutter] - flutter_linkify 5.0.2 [flutter linkify] - 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.0.3 [flutter meta path_drawing vector_math xml] - http 0.13.4 [async http_parser meta path] - image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface] - jwt_decoder 2.0.1 - mobile_scanner 1.1.0 [flutter flutter_web_plugins js] - provider 6.0.3 [collection flutter nested] - sentry_flutter 6.6.1 [flutter flutter_web_plugins sentry package_info_plus meta] - url_launcher 6.1.5 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - video_player 2.4.7 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web] dev dependencies: - change_app_package_name 1.1.0 - flutter_launcher_icons 0.9.2 [args image path yaml] - flutter_lints 1.0.4 [lints] - flutter_native_splash 1.3.3 [args image meta path xml yaml universal_io] - 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] transitive dependencies: - _flutterfire_internals 1.0.7 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - archive 3.1.8 [crypto path] - args 2.3.0 - async 2.9.0 [collection meta] - boolean_selector 2.1.0 [source_span string_scanner] - 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 - clock 1.1.1 - cloud_firestore_platform_interface 5.8.4 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.0.4 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.16.0 - cross_file 0.3.3+1 [js meta] - crypto 3.0.1 [collection typed_data] - csslib 0.17.1 [source_span] - fake_async 1.3.1 [clock collection] - ffi 1.1.2 - file 6.1.2 [meta path] - firebase_core_platform_interface 4.5.2 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.0.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 4.2.5 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.2.5 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - 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_plugin_android_lifecycle 2.0.5 [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] - html 0.15.0 [csslib source_span] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - image 3.1.1 [archive meta xml] - image_picker_android 0.8.4+13 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_for_web 2.1.6 [flutter flutter_web_plugins image_picker_platform_interface] - image_picker_ios 0.8.5+4 [flutter image_picker_platform_interface] - image_picker_platform_interface 2.4.4 [cross_file flutter http plugin_platform_interface] - js 0.6.4 - linkify 4.1.0 - lints 1.0.1 - matcher 0.12.12 [stack_trace] - material_color_utilities 0.1.5 - meta 1.8.0 - nested 1.0.0 [flutter] - octo_image 1.0.2 [flutter flutter_blurhash] - package_info_plus 1.4.2 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web] - 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 1.0.5 [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 2.0.10 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - 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.6 [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.0.6 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - petitparser 4.4.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.3 [meta] - process 4.2.4 [file path platform] - rxdart 0.27.3 - sentry 6.6.1 [http meta stack_trace uuid] - sky_engine 0.0.99 - 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] - string_scanner 1.1.1 [source_span] - synchronized 3.0.0+2 - term_glyph 1.2.1 - test_api 0.4.12 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.0 [collection] - universal_io 2.0.4 [collection crypto meta typed_data] - url_launcher_android 6.0.15 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.15 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.0 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.0 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.0 [flutter plugin_platform_interface] - url_launcher_web 2.0.8 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.0 [flutter url_launcher_platform_interface] - uuid 3.0.6 [crypto] - vector_math 2.1.2 - video_player_android 2.3.8 [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.6 [flutter flutter_web_plugins pedantic video_player_platform_interface] - win32 2.5.2 [ffi] - xdg_directories 0.2.0+1 [meta path process] - xml 5.3.1 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```

darshankawar commented 1 year ago

Thanks for the report @downhamd There was a similar recent issue https://github.com/firebase/flutterfire/issues/9822 reported which, according to OP and another commenter, got resolved after upgrading to 3.3.7 and Xcode to 14.1, but looking at the details you shared, you already seem to be on same config.

Is this only happening on iOS simulator or physical device too ?

Sultan-dev commented 1 year ago

I am facing this issue also, and I did as same as in #9822 but it still does not work.

This happened to me after upgrading flutter from 3.3.6 to 3.3.7, and after upgrading Xcode from 14.0.1 to 14.1.

flutter doctor -v log:

Click me ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.7, on macOS 13.0 22A380 darwin-arm, locale en-SA) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] IntelliJ IDEA Community Edition (version 2022.2.3) [✓] VS Code (version 1.73.0) [✓] Connected device (4 available) [✓] HTTP Host Availability • No issues found! s_alkhubayzi@Sultans-MacBook-Pro ios % flutter doctor -v [✓] Flutter (Channel stable, 3.3.7, on macOS 13.0 22A380 darwin-arm, locale en-SA) • Flutter version 3.3.7 on channel stable at /Users/s_alkhubayzi/Development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision e99c9c7cd9 (7 days ago), 2022-11-01 16:59:00 -0700 • Engine revision 857bd6b74c • Dart version 2.18.4 • DevTools version 2.15.0 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /Users/s_alkhubayzi/Library/Android/sdk • Platform android-33, build-tools 33.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14B47b • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2022.2.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] VS Code (version 1.73.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.52.0 [✓] Connected device (4 available) • sdk gphone64 arm64 (mobile) • emulator-5556 • android-arm64 • Android 12 (API 32) (emulator) • iPhone 14 Pro (mobile) • 13F43F43-EF92-4096-96AA-94DC85DAF0A8 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.0 22A380 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.87 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ```

flutter pub deps -- --style=compact log:

Click me ``` Dart SDK 2.18.4 Flutter SDK 3.3.7 mar 1.0.5+15 dependencies: - cached_network_image 3.2.2 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - cloud_firestore 4.0.2 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_functions 4.0.2 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - connectivity_plus 3.0.2 [flutter flutter_web_plugins connectivity_plus_platform_interface js meta nm] - crypto 3.0.2 [typed_data] - cupertino_icons 1.0.5 - dropdown_search 5.0.3 [flutter] - firebase_analytics 10.0.2 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 4.0.2 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.1.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 3.0.2 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_messaging 14.0.2 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_remote_config 3.0.2 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_local_notifications 9.9.1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math] - google_sign_in 5.4.2 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web] - http 0.13.5 [async http_parser meta path] - intl 0.17.0 [clock path] - package_info_plus 3.0.1 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - pdf_render 1.3.4 [collection flutter flutter_web_plugins js plugin_platform_interface vector_math] - provider 6.0.4 [collection flutter nested] - rate_my_app 1.1.3 [shared_preferences flutter_rating_bar flutter] - share_plus 6.0.1 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher ffi win32] - 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] - sign_in_with_apple 4.1.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web] - url_launcher 6.1.6 [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.6 [crypto] dev dependencies: - 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] transitive dependencies: - _flutterfire_internals 1.0.5 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - args 2.3.1 - async 2.9.0 [collection meta] - boolean_selector 2.1.0 [source_span string_scanner] - 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 - clock 1.1.1 - cloud_firestore_platform_interface 5.8.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.0.2 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.1.21 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.3.10 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.16.0 - connectivity_plus_platform_interface 1.2.3 [flutter meta plugin_platform_interface] - cross_file 0.3.3+2 [js meta] - dbus 0.7.8 [args ffi meta xml] - fake_async 1.3.1 [clock collection] - ffi 2.0.1 - file 6.1.4 [meta path] - firebase_analytics_platform_interface 3.3.10 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.1+1 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth_platform_interface 6.10.4 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.0.2 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.5.1 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.0.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.3.3 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 4.2.3 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.2.3 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_remote_config_platform_interface 1.1.22 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_remote_config_web 1.1.11 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins js] - 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_local_notifications_linux 0.5.1 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories] - flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface] - flutter_rating_bar 4.0.1 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - google_sign_in_android 6.1.1 [flutter google_sign_in_platform_interface] - google_sign_in_ios 5.5.0 [flutter google_sign_in_platform_interface] - google_sign_in_platform_interface 2.3.0 [flutter plugin_platform_interface quiver] - google_sign_in_web 0.10.2 [flutter flutter_web_plugins google_sign_in_platform_interface js] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - js 0.6.4 - 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] - octo_image 1.0.2 [flutter flutter_blurhash] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.2 - path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - path_provider_android 2.0.20 [flutter path_provider_platform_interface] - path_provider_ios 2.0.11 [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.5 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.3 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - petitparser 5.0.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.3 [meta] - process 4.2.4 [file path platform] - quiver 3.1.0 [matcher] - rxdart 0.27.5 - share_plus_platform_interface 3.1.2 [cross_file flutter meta mime plugin_platform_interface] - shared_preferences_android 2.0.14 [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.1.0 [flutter plugin_platform_interface] - 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] - sign_in_with_apple_platform_interface 1.0.0 [flutter plugin_platform_interface meta] - sign_in_with_apple_web 1.0.1 [flutter flutter_web_plugins sign_in_with_apple_platform_interface js] - sky_engine 0.0.99 - source_span 1.9.0 [collection path term_glyph] - sqflite 2.1.0+1 [flutter sqflite_common path] - sqflite_common 2.3.0 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - string_scanner 1.1.1 [source_span] - synchronized 3.0.0+3 - term_glyph 1.2.1 - test_api 0.4.12 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.8.0 [path] - typed_data 1.3.1 [collection] - url_launcher_android 6.0.19 [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.1.1 [flutter plugin_platform_interface] - url_launcher_web 2.0.13 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface] - vector_math 2.1.2 - win32 3.0.1 [ffi] - xdg_directories 0.2.0+2 [meta path process] - xml 6.1.0 [collection meta petitparser] ```
downhamd commented 1 year ago

Hi @darshankawar. I can confirm that this is only happening on the iOS emulator. On the Android emulator there is no error message after subscribing to topics. And push notifications work fine on physical devices for both iOS and Android.

darshankawar commented 1 year ago

Thanks for the update @downhamd From the code sample you provided, you seem to be using third party plugins such as provider. If possible, please provide complete minimal code sample without any third party plugin code that still triggers the error, so that we can use it to verify the reported behavior.

I tried the official plugin example and ran it on simulator with latest plugin versions and didn't get the issue.

downhamd commented 1 year ago

No problem @darshankawar , I have removed the dependence on provider and simplified the code:

  List<String> notificationTopics = [
    'topic1',
    'topic2',
    'topic3',
  ];

  Future<void> requestMessagingPermission() async {
    FirebaseMessaging messaging = FirebaseMessaging.instance;

    NotificationSettings settings = await messaging.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      sound: true,
    );

    print('User granted permission: ${settings.authorizationStatus}');

    if (settings.authorizationStatus == AuthorizationStatus.authorized) {
      print('User granted notifiactions permission');

      messaging.getToken().then((token) async {
        print('Messaging token: $token');

        //configure notification topics
        //gets a list of strings (topic names) from provider and loops through them to subscribe to them all

        //subscribes to topics
        for (var topic in notificationTopics) {
          print('topic subscribing... $topic');

          try {
            await messaging.subscribeToTopic(topic).then((value) => print('topic subscribed: $topic'));
          } catch (e) {
            print('subscription error: $e');
          }
        }
      });
    }
  }
darshankawar commented 1 year ago

Thanks for the update. I tried the same using plugin example and by subscribing to topic, I was able to successfully susbscribe it running on iOS simulator:

Syncing files to device iPhone 13 Pro...
flutter: Token monitor set null
flutter: FCM Token: cqmTvKvW_UCss1_YEatfwU:APA91bGA4lddsZJs-DhC9-6-R-mWuRM2hrGV-n2-IdKlUydRqcSMI2JXtUwVYi6pgK-WJgLu-IMF3ILU9Pb012xLuv-IiVKx-qheVl8ELRkKixXYdnzfGxkw4UaS9BWqZkO6ly2b1erL
flutter: Token monitor set null
flutter: FlutterFire Messaging Example: Subscribing to topic "fcm_test".
flutter: FlutterFire Messaging Example: Subscribing to topic "fcm_test" successful.
flutter: FlutterFire Messaging Example: Subscribing to topic "fcm_test".
flutter: FlutterFire Messaging Example: Subscribing to topic "fcm_test" successful.

But looking at the frequency of such issues like this and also below, I am keeping this issue open and labeling for further insights from the team.

https://github.com/firebase/flutterfire/issues/9822 https://github.com/firebase/flutterfire/issues/9878

darshankawar commented 1 year ago

/cc @russellwheatley

russellwheatley commented 1 year ago

tested using the following in main.dart:

// ignore_for_file: require_trailing_commas
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  Future<void> requestMessagingPermission() async {
    FirebaseMessaging messaging = FirebaseMessaging.instance;

    NotificationSettings settings = await messaging.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      sound: true,
    );

    print('User granted permission: ${settings.authorizationStatus}');

    if (settings.authorizationStatus == AuthorizationStatus.authorized) {
      print('User granted notifiactions permission');

      final token = await messaging.getToken();
      print('Messaging token: $token');

      //subscribe to topics
      for (final topic in ['some', 'new', 'topics']) {
        print('topic subscribing... $topic');

        try {
          await messaging
              .subscribeToTopic(topic)
              .then((value) => print('topic subscribed: $topic'));
        } catch (e) {
          print('subscription error: $e');
        }
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Testing Something'),
          ),
          body: ElevatedButton(
            onPressed: () async {
              await requestMessagingPermission();
            },
            child: const Text('press me'),
          )),
    );
  }
}

Got the following console results:

2023-02-16 13:37:48.660351+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: User granted permission: AuthorizationStatus.authorized
2023-02-16 13:37:48.660413+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: User granted notifiactions permission
2023-02-16 13:37:50.169431+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribing... some
2023-02-16 13:37:50.999551+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribed: some
2023-02-16 13:37:50.999794+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribing... new
2023-02-16 13:37:51.201856+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribed: new
2023-02-16 13:37:51.202186+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribing... topics
2023-02-16 13:37:51.516142+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribed: topics

flutter doctor:

[✓] Flutter (Channel stable, 3.7.3, on macOS 12.5.1 21G83 darwin-arm64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
    ✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Community Edition (version 2020.1.1)
[✓] VS Code (version 1.75.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

There's something wrong with your setup. I'm guessing something to do with method swizzling. Read the documentation here to see if this is your issue.

google-oss-bot commented 1 year ago

Hey @downhamd. 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 1 year ago

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

@downhamd 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.