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

🐛 [firebase_messaging] Sending notifications to token always returns "NotRegistered" #6542

Closed cadaniel closed 3 years ago

cadaniel commented 3 years ago

Bug report

Describe the bug So I'm trying to send notifications, and I keep getting an error saying token is not registered.

I've freshly installed the app and given notification permissions. I take the token and place it into

Steps to reproduce

Steps to reproduce the behavior:

  1. Request FCM token from firebase messaging
  2. Copy FCM token from console/debugger into postman
  3. Get NotRegistered error

Expected behavior

Token sends notification to device

Sample project

Will try and update with one soon


Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` • Android SDK at /Users/casey/Library/Android/sdk • Platform android-30, build-tools 30.0.3 • Java binary at: /Users/casey/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7351085/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5.1, Build version 12E507 • CocoaPods version 1.10.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.2) • Android Studio at /Users/casey/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7351085/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.8+10-b944.6916264) [✓] IntelliJ IDEA Ultimate Edition (version 2021.1.2) • IntelliJ at /Users/casey/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app • Flutter plugin version 58.0.3 • Dart plugin version 211.7665 [✓] Connected device (4 available) • Casey’s iPhone (mobile) • 00008030-001A20E83C78802E • ios • iOS 14.6 • iPhone 12 Pro Max (mobile) • 9F2B654C-42A3-4578-BE0E-D780E396F04A • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator) • iPhone 11 (mobile) • 1AD57844-0FB8-4309-B473-A38E1403B152 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator) • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.106 ! Doctor found issues in 1 category. ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 2.13.3 Flutter SDK 2.2.2 normative 1.3.1 dependencies: - animated_widgets 1.1.0 [flutter vector_math] - auto_size_text 3.0.0-nullsafety.0 [flutter] - bloc 7.0.0 [meta] - carousel_slider 4.0.0 [flutter] - cupertino_icons 1.0.3 - date_utils 0.2.0 [intl] - dio 4.0.0 [http_parser path] - f_health 0.0.1 [flutter] - firebase_analytics 8.1.2 [firebase_analytics_platform_interface firebase_analytics_web firebase_core flutter meta] - firebase_auth 2.0.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 1.3.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 2.0.6 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_messaging 10.0.3 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - fl_chart 0.35.0 [flutter equatable pedantic] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_bloc 7.0.1 [flutter bloc provider] - flutter_signin_button 2.0.0 [flutter font_awesome_flutter] - flutter_svg 0.22.0 [flutter meta path_drawing vector_math xml] - font_awesome_flutter 9.1.0 [flutter] - freezed_annotation 0.14.2 [collection json_annotation meta] - get_it 7.1.3 [async collection] - google_fonts 2.1.0 [flutter http path_provider crypto] - google_sign_in 5.0.4 [google_sign_in_platform_interface google_sign_in_web flutter meta] - injectable 1.4.1 [get_it] - intl 0.17.0 [clock path] - logging 1.0.1 - moor 4.3.2 [async convert collection meta pedantic stream_channel sqlite3] - numberpicker 2.1.1 [flutter infinite_listview] - package_info 2.0.2 [flutter] - path_provider 2.0.2 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows] - polygon_clipper 1.0.2 [flutter] - provider 5.0.0 [collection flutter nested] - purchases_flutter 3.2.2 [flutter collection] - shared_preferences 2.0.6 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows] - sign_in_with_apple 3.0.0 [flutter meta] - sqlite3_flutter_libs 0.4.3 [flutter] - url_launcher 6.0.6 [flutter meta url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - workmanager 0.4.1 [flutter] dev dependencies: - bloc_test 8.0.0 [bloc meta mocktail test] - build_runner 2.0.4 [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_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] - freezed 0.14.2 [analyzer build build_config collection meta source_gen freezed_annotation] - injectable_generator 1.4.1 [build source_gen path glob analyzer code_builder dart_style injectable collection] - json_serializable 4.1.3 [analyzer build build_config collection json_annotation meta path source_gen] - mockito 5.0.5 [analyzer build code_builder collection dart_style matcher meta path source_gen test_api] - moor_generator 4.3.1 [charcode collection recase meta path json_annotation stream_transform args logging cli_util moor sqlite3 sqlparser analyzer analyzer_plugin_fork source_span package_config pub_semver build build_resolvers build_config dart_style source_gen] transitive dependencies: - _fe_analyzer_shared 22.0.0 [meta] - analyzer 1.7.1 [_fe_analyzer_shared cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml pedantic] - analyzer_plugin_fork 0.5.1 [analyzer dart_style meta pub_semver] - args 2.1.1 - async 2.6.1 [meta collection] - boolean_selector 2.1.0 [source_span string_scanner] - build 2.0.2 [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.3 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.0.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.0.0 - built_value 8.0.6 [built_collection collection fixnum] - characters 1.1.0 - charcode 1.2.0 - checked_yaml 2.0.1 [json_annotation source_span yaml] - cli_util 0.3.0 [meta path] - clock 1.1.0 - code_builder 4.0.0 [built_collection built_value collection matcher meta] - collection 1.15.0 - convert 3.0.0 [typed_data] - coverage 1.0.3 [args logging package_config path source_maps stack_trace vm_service] - crypto 3.0.1 [collection typed_data] - dart_style 2.0.1 [analyzer args path pub_semver source_span] - equatable 2.0.2 [collection meta] - fake_async 1.2.0 [clock collection] - ffi 1.1.2 - file 6.1.1 [meta path] - firebase 9.0.1 [http http_parser js] - firebase_analytics_platform_interface 2.0.1 [flutter meta] - firebase_analytics_web 0.3.0+1 [firebase firebase_analytics_platform_interface flutter flutter_web_plugins meta] - firebase_auth_platform_interface 5.0.0 [firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 2.0.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.0.1 [collection flutter meta plugin_platform_interface] - firebase_core_web 1.1.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.0.6 [collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 3.0.2 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 2.0.2 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - fixnum 1.0.0 - flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math] - frontend_server_client 2.1.0 [async path] - glob 2.0.1 [async collection file path pedantic string_scanner] - google_sign_in_platform_interface 2.0.1 [flutter meta quiver] - google_sign_in_web 0.10.0 [google_sign_in_platform_interface flutter flutter_web_plugins meta js] - graphs 2.0.0 - 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] - infinite_listview 1.1.0 [flutter] - io 1.0.0 [meta path string_scanner] - js 0.6.3 - json_annotation 4.0.1 - matcher 0.12.10 [stack_trace] - meta 1.3.0 - mime 1.0.0 - mocktail 0.1.4 [collection matcher test] - nested 1.0.0 [flutter] - node_preamble 2.0.0 - package_config 2.0.0 [path] - path 1.8.0 - path_drawing 0.5.1 [vector_math meta path_parsing flutter] - path_parsing 0.2.1 [vector_math meta] - path_provider_linux 2.0.0 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 2.0.0 [flutter] - path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface] - path_provider_windows 2.0.1 [path_provider_platform_interface meta path flutter ffi win32] - pedantic 1.11.0 - petitparser 4.1.0 [meta] - platform 3.0.0 - plugin_platform_interface 2.0.0 [meta] - pool 1.5.0 [async stack_trace] - process 4.2.1 [file path platform] - pub_semver 2.0.0 [collection] - pubspec_parse 1.0.0 [checked_yaml collection json_annotation pub_semver yaml] - quiver 3.0.1 [matcher] - recase 4.0.0 - shared_preferences_linux 2.0.0 [flutter file meta path path_provider_linux shared_preferences_platform_interface] - shared_preferences_macos 2.0.0 [shared_preferences_platform_interface flutter] - shared_preferences_platform_interface 2.0.0 [flutter] - shared_preferences_web 2.0.0 [shared_preferences_platform_interface flutter flutter_web_plugins meta] - shared_preferences_windows 2.0.0 [shared_preferences_platform_interface flutter file meta path path_provider_platform_interface path_provider_windows] - shelf 1.1.4 [async collection http_parser path stack_trace stream_channel] - shelf_packages_handler 3.0.0 [path shelf shelf_static] - shelf_static 1.0.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.0.2 [analyzer async build dart_style glob meta path pedantic source_span yaml] - source_map_stack_trace 2.1.0 [path stack_trace source_maps] - source_maps 0.10.10 [source_span] - source_span 1.8.1 [collection path term_glyph] - sqlite3 1.1.2 [collection ffi meta] - sqlparser 0.16.0 [meta collection source_span charcode] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.0 - string_scanner 1.1.0 [charcode source_span] - term_glyph 1.2.0 - test 1.16.8 [analyzer async boolean_selector collection coverage http_multi_server io js node_preamble package_config path pedantic 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.3.0 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - test_core 0.3.19 [analyzer async args boolean_selector collection coverage glob io meta package_config path pedantic 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.0 [collection] - url_launcher_linux 2.0.0 [flutter] - url_launcher_macos 2.0.0 [flutter] - url_launcher_platform_interface 2.0.3 [flutter plugin_platform_interface] - url_launcher_web 2.0.1 [flutter flutter_web_plugins meta url_launcher_platform_interface] - url_launcher_windows 2.0.0 [flutter] - vector_math 2.1.0 - vm_service 6.2.0 - watcher 1.0.0 [async path pedantic] - web_socket_channel 2.1.0 [async crypto stream_channel] - webkit_inspection_protocol 1.0.0 [logging] - win32 2.1.5 [ffi] - xdg_directories 0.2.0 [meta path process] - xml 5.1.2 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```

cadaniel commented 3 years ago

Is there a new token method? Older tokens don't have a ":" near the start, where ones generated now do.

Did 8.0 update that?

markusaksli-nc commented 3 years ago

Hi @cadaniel To be clear you are experiencing this with an iOS device? Are you sure you aren't adding breaks to the token or anything to the end where you copy it? Thank you

cadaniel commented 3 years ago

I was experiencing this with iOS physical devices.

I was not inserting any breaks, and this was happening with multiple tokens.

The old REST API seems to be broken with the new token format from version 8.0.0

What seemed to happen is (yet again) the iOS SDK updated without me updating the flutter dependency first. This has happened multiple times to me in the past.

Is it possible to lock the iOS firebase dependency to a flutterfire version? Because this is getting old really fast.

markusaksli-nc commented 3 years ago

That shouldn't be possible. The FlutterFire plugins internally manage the SDK version so it should only change once you update the iOS SDK. How exactly are you sending the notification (if you could provide code that would be great) and could you provide the exact error and stacktrace?

cadaniel commented 3 years ago

he FlutterFire plugins internally manage the SDK version so it should only change once you update the iOS SDK.

Has not been my experience. I was getting the new token format that contains a ":" character near the start-ish of the token before upgrading to version 8.

I don't have a stack trace, I was using POSTMAN to send https://fcm.googleapis.com/fcm/send and kept getting the error mentioned.

Odly enough, going through my postman history, all the request I sent yesterday that gave the error meniotned, now work. So I have no idea whats happening there.

A similar time this happened was

https://github.com/FirebaseExtended/flutterfire/issues/5964

To solve that I had to nuke cocapods and pubspec cache from orbit and locked the pubspec version. It was working one day, and not working the next with no changes to that code.

markusaksli-nc commented 3 years ago

Well unless we are able to reproduce the issue it's really hard to tell what is going on or where a fix could be needed. You could try filing this in https://github.com/firebase/firebase-ios-sdk but since the behavior is sporadic I'll close the issue here for now.