[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [firebase_messaging] An unknown error occurred while calling method Messaging#getToken #10656

Closed
Tom3652 opened this issue Mar 24, 2023 · 44 comments · Fixed by #11400
Closed
Assignees
Labels
platform: ios Issues / PRs which are specifically for iOS. plugin: messaging resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working

Comments

@Tom3652
Copy link
Tom3652 commented Mar 24, 2023

Bug report

Describe the bug

It's the same as #9878 but happening in release mode only in my TestFlight iOS app.
I do see many Crashlytics reports regarding this issue while in debug mode during development everything is fine, even if i build in release / profile mode and test it myself.

Non-fatal Exception: FlutterError
0  ???                            0x0 StandardMethodCodec.decodeEnvelope + 653 (message_codecs.dart:653)
1  ???                            0x0 MethodChannel._invokeMethod + 315 (platform_channel.dart:315)
2  ???                            0x0 MethodChannel.invokeMapMethod + 518 (platform_channel.dart:518)
3  ???                            0x0 MethodChannelFirebaseMessaging.getToken + 224 (method_channel_messaging.dart:224)
4  ???                            0x0 NotificationViewModel._getToken + 76 (notification_view_model.dart:76)

This is happening with firebase_messaging: ^14.3.0 :

Capture d’écran 2023-03-24 à 19 40 18

I am calling String token = await FirebaseMessaging.instance.getToken() ?? ""; this way right after :

 NotificationSettings settings = await FirebaseMessaging.instance.requestPermission(sound: true, carPlay: true);
 if (settings.authorizationStatus == AuthorizationStatus.authorized) {
      String token = await FirebaseMessaging.instance.getToken() ?? "";
}

Steps to reproduce

Even with #9878 steps i can't reproduce it anymore but it happens to my users from TestFlight (iOS only)

Expected behavior

Either this error not happening or seeing at least another message than [FlutterError - [firebase_messaging/unknown] An unknown error has occurred.] because when we look at the trace, this is coming from inside the plugin method so i don't know how can i fix it or even if i can fix it myself :/


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.8, on macOS 13.2.1 22D68 darwin-x64, locale fr-FR)                                                                                                                                                    Checking Android licenses is taking an unexpectedly long time...[✓] 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 2022.1)
[✓] VS Code (version 1.76.2)
[✓] Connected device (2 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.19.5
Flutter SDK 3.7.8
myappname 0.0.1+1

dependencies:
- audio_session 0.1.13 [flutter flutter_web_plugins rxdart meta]
- audio_waveforms 1.0.1 [flutter]
- audioplayers 3.0.1 [audioplayers_android audioplayers_darwin audioplayers_linux audioplayers_platform_interface audioplayers_web audioplayers_windows flutter http path_provider uuid]
- auto_size_text 3.0.0 [flutter]
- cached_network_image 3.2.3 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- collection 1.17.0
- connectivity_plus 3.0.3 [flutter flutter_web_plugins connectivity_plus_platform_interface js meta nm]
- crypto 3.0.2 [typed_data]
- cupertino_icons 1.0.5
- desktop_drop 0.4.1 [flutter flutter_web_plugins cross_file]
- dio 5.0.3 [http_parser meta path]
- extended_image 7.0.2 [extended_image_library flutter meta]
- file_selector 0.9.2+4 [file_selector_ios file_selector_linux file_selector_macos file_selector_platform_interface file_selector_web file_selector_windows flutter]
- firebase_analytics 10.1.6 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_app_check 0.1.1+14 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter]
- firebase_auth 4.3.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 2.8.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 3.0.17 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_messaging 14.3.0 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_performance 0.9.0+16 [firebase_core firebase_core_platform_interface firebase_performance_platform_interface firebase_performance_web flutter]
- flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine]
- flutter_app_badger 1.5.0 [flutter]
- flutter_calendar_carousel 2.4.2 [intl flutter]
- flutter_image_compress 1.1.3 [flutter]
- flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math]
- flutter_native_splash 2.2.19 [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_staggered_grid_view 0.6.2 [flutter]
- gallery_saver 2.3.2 [flutter path_provider http path]
- google_sign_in 6.0.2 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- hive_flutter 1.1.0 [flutter hive path_provider path]
- http 0.13.5 [async http_parser meta path]
- image_editor 1.3.0 [flutter image_editor_platform_interface image_editor_common]
- image_picker 0.8.7 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- in_app_review 2.0.6 [flutter in_app_review_platform_interface]
- linkify 4.1.0
- local_auth 2.1.6 [flutter local_auth_android local_auth_ios local_auth_platform_interface local_auth_windows]
- maps_launcher 2.2.0 [flutter flutter_web_plugins url_launcher]
- path_provider 2.0.13 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- permission_handler 10.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- provider 6.0.5 [collection flutter nested]
- pull_to_refresh_flutter3 2.0.1 [flutter]
- purchases_flutter 4.11.0 [flutter freezed_annotation json_annotation]
- record 4.4.4 [flutter record_platform_interface record_web record_windows record_macos record_linux]
- rive 0.10.3 [collection flutter flutter_web_plugins http meta plugin_platform_interface rive_common]
- 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]
- sign_in_with_apple 4.3.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web]
- 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]

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]
- 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]
- hive_generator 2.0.0 [build source_gen hive analyzer source_helper]

transitive dependencies:
- _fe_analyzer_shared 56.0.0 [meta]
- _flutterfire_internals 1.0.18 [collection firebase_core firebase_core_platform_interface flutter meta]
- analyzer 5.8.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]
- audioplayers_android 2.0.0 [audioplayers_platform_interface flutter]
- audioplayers_darwin 3.0.1 [audioplayers_platform_interface flutter]
- audioplayers_linux 1.0.4 [audioplayers_platform_interface flutter]
- audioplayers_platform_interface 4.0.0 [flutter plugin_platform_interface]
- audioplayers_web 2.2.0 [audioplayers_platform_interface flutter flutter_web_plugins js]
- audioplayers_windows 1.1.3 [audioplayers_platform_interface flutter]
- 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.2.0 [analyzer async build collection 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.4 [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_platform_interface 1.2.4 [flutter meta plugin_platform_interface]
- convert 3.1.1 [typed_data]
- cross_file 0.3.3+4 [js meta]
- csslib 0.17.2 [source_span]
- dart_style 2.3.0 [analyzer args path pub_semver source_span]
- dbus 0.7.8 [args ffi meta xml]
- extended_image_library 3.4.1 [crypto flutter http_client_helper path path_provider]
- fake_async 1.3.1 [clock collection]
- ffi 2.0.1
- file 6.1.4 [meta path]
- file_selector_ios 0.5.1+1 [file_selector_platform_interface flutter]
- file_selector_linux 0.9.1+2 [cross_file file_selector_platform_interface flutter]
- file_selector_macos 0.9.0+6 [cross_file file_selector_platform_interface flutter]
- file_selector_platform_interface 2.4.1 [cross_file flutter http plugin_platform_interface]
- file_selector_web 0.9.0+4 [file_selector_platform_interface flutter flutter_web_plugins]
- file_selector_windows 0.9.1+6 [cross_file file_selector_platform_interface flutter]
- firebase_analytics_platform_interface 3.3.23 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.5.1+14 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_app_check_platform_interface 0.0.5+17 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_app_check_web 0.0.7+17 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_auth_platform_interface 6.12.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.2.10 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.5.3 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.2.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics_platform_interface 3.3.17 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 4.2.16 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.2.17 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_performance_platform_interface 0.1.1+35 [_flutterfire_internals firebase_core flutter plugin_platform_interface]
- firebase_performance_web 0.1.1+24 [_flutterfire_internals firebase_core firebase_core_web firebase_performance_platform_interface flutter flutter_web_plugins js]
- 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_plugin_android_lifecycle 2.0.9 [flutter]
- 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]
- freezed_annotation 2.2.0 [collection json_annotation meta]
- frontend_server_client 3.2.0 [async path]
- glob 2.1.1 [async collection file path string_scanner]
- google_identity_services_web 0.2.0 [js meta]
- google_sign_in_android 6.1.8 [flutter google_sign_in_platform_interface]
- google_sign_in_ios 5.6.1 [flutter google_sign_in_platform_interface]
- google_sign_in_platform_interface 2.3.1 [flutter plugin_platform_interface quiver]
- google_sign_in_web 0.11.0+2 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http js]
- graphs 2.2.0 [collection]
- hive 2.2.3 [meta crypto]
- html 0.15.2 [csslib source_span]
- http_client_helper 2.0.3 [http]
- 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]
- image_editor_common 1.0.1 [flutter image_editor_platform_interface]
- image_editor_platform_interface 1.0.1 [flutter platform plugin_platform_interface]
- image_picker_android 0.8.6+5 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 2.1.12 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_ios 0.8.7+1 [flutter image_picker_platform_interface]
- image_picker_platform_interface 2.6.3 [cross_file flutter http plugin_platform_interface]
- in_app_review_platform_interface 2.0.4 [flutter url_launcher plugin_platform_interface platform]
- intl 0.17.0 [clock path]
- io 1.0.4 [meta path string_scanner]
- js 0.6.5 [meta]
- json_annotation 4.8.0 [meta]
- lints 2.0.1
- local_auth_android 1.0.21 [flutter flutter_plugin_android_lifecycle intl local_auth_platform_interface]
- local_auth_ios 1.1.1 [flutter intl local_auth_platform_interface]
- local_auth_platform_interface 1.0.7 [flutter plugin_platform_interface]
- local_auth_windows 1.0.7 [flutter local_auth_platform_interface]
- logging 1.1.1
- matcher 0.12.13 [meta stack_trace]
- material_color_utilities 0.2.0
- meta 1.8.0
- mime 1.0.4
- nested 1.0.0 [flutter]
- nm 0.5.0 [dbus]
- octo_image 1.0.2 [flutter flutter_blurhash]
- package_config 2.1.0 [path]
- path 1.8.2
- path_provider_android 2.0.24 [flutter path_provider_platform_interface]
- path_provider_foundation 2.2.0 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.10 [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.5 [ffi flutter path path_provider_platform_interface win32]
- pedantic 1.11.1
- permission_handler_android 10.2.0 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.0.7 [flutter permission_handler_platform_interface]
- permission_handler_platform_interface 3.9.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.1.2 [flutter permission_handler_platform_interface]
- petitparser 5.1.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.4 [meta]
- pointycastle 3.7.0 [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.2 [checked_yaml collection json_annotation pub_semver yaml]
- quiver 3.2.1 [matcher]
- record_linux 0.4.1 [flutter record_platform_interface path]
- record_macos 0.2.2 [flutter record_platform_interface]
- record_platform_interface 0.5.0 [flutter plugin_platform_interface]
- record_web 0.5.0 [flutter flutter_web_plugins record_platform_interface]
- record_windows 0.7.1 [flutter record_platform_interface path]
- rive_common 0.0.3 [flutter flutter_web_plugins collection ffi graphs http meta plugin_platform_interface]
- rxdart 0.27.7
- share_plus_platform_interface 3.2.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid]
- 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]
- 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_gen 1.2.7 [analyzer async build dart_style glob 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.6 [flutter sqflite_common path]
- sqflite_common 2.4.3 [synchronized path meta]
- stack_trace 1.11.0 [path]
- 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]
- timing 1.0.1 [json_annotation]
- typed_data 1.3.1 [collection]
- universal_io 2.2.0 [collection meta typed_data]
- url_launcher_android 6.0.25 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.1.3 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.4 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.4 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.1.2 [flutter plugin_platform_interface]
- url_launcher_web 2.0.16 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.5 [flutter url_launcher_platform_interface]
- vector_math 2.1.4
- watcher 1.0.2 [async path]
- web_socket_channel 2.3.0 [async crypto stream_channel]
- win32 3.1.3 [ffi]
- xdg_directories 1.0.0 [meta path process]
- xml 6.2.2 [collection meta petitparser]
- yaml 3.1.1 [collection source_span string_scanner]

@Tom3652 Tom3652 added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Mar 24, 2023
@jpears1
Copy link
jpears1 commented Mar 24, 2023

I'm seeing the same exception being throw by getToken, also firebase_messaging ^14.3.0 (firebase_core: ^2.8.0).

For me, it happens with both debug and release builds.

And it seems to only happen the first time getToken is called after initially installing the app. Subsequent calls to it (such as quitting and then restarting the app) seem to always succeed. Once a token is obtained, if the app deletes the token and then calls getToken again, it succeeds; i..e, truly only seeing it fail on the first getToken attempt after an initial install.

If I go back to an earlier branch of our app's code, that was using firebase_messaging ^14.2.5 (firebase_core: ^2.7.0) then all is OK.

flutter doctor...

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.8, on macOS 13.2.1 22D68 darwin-arm64, locale en-US)
[✓] 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.3)
[✓] VS Code (version 1.76.2)
[✓] Connected device (5 available)
[✓] HTTP Host Availability

• No issues found!

flutter pub deps -- --style=compact...

Dart SDK 2.19.5
Flutter SDK 3.7.8
workvis 1.0.0+19

dependencies:
- app_settings 4.2.0 [flutter]
- charts_flutter 0.12.0 [charts_common collection flutter intl logging meta]
- clippy_flutter 2.0.0-nullsafety.1 [flutter]
- collection 1.17.0
- cupertino_icons 1.0.5
- custom_info_window 1.0.1 [flutter google_maps_flutter]
- dio 5.0.3 [http_parser meta path]
- dropdown_button2 2.0.0 [flutter meta]
- duration 3.0.12
- enum_to_string 2.0.1
- expandable 5.0.1 [flutter]
- firebase_core 2.8.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 14.3.0 [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_easy_treeview 1.0.6 [flutter quiver collection]
- flutter_local_notifications 13.0.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_phoenix 1.1.0 [flutter]
- flutter_platform_widgets 3.0.0 [flutter cupertino_icons]
- 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.4 [flutter vector_graphics vector_graphics_codec vector_graphics_compiler]
- google_maps_flutter 2.2.5 [flutter google_maps_flutter_android google_maps_flutter_ios google_maps_flutter_platform_interface]
- google_maps_flutter_web 0.4.0+7 [flutter flutter_web_plugins google_maps google_maps_flutter_platform_interface sanitize_html stream_transform]
- http_status_code 0.0.2
- intl 0.17.0 [clock path]
- json_annotation 4.8.0 [meta]
- json_serializable 6.6.1 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]
- logging 1.1.1
- need_resume 1.0.7+1 [flutter]
- package_info_plus 3.0.2 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32]
- permission_handler 10.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- provider 6.0.5 [collection flutter nested]
- settings_ui 2.0.2 [flutter]
- 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]
- stack 0.2.1
- timezone 0.9.1 [path]
- tuple 2.0.1
- video_player 2.6.0 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web]
- video_player_web_hls 1.0.0+2 [flutter flutter_web_plugins http video_player_platform_interface js]
- webview_flutter 4.0.2 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview]

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]
- 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]

transitive dependencies:
- _fe_analyzer_shared 52.0.0 [meta]
- _flutterfire_internals 1.0.18 [collection firebase_core firebase_core_platform_interface flutter meta]
- analyzer 5.4.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- args 2.3.2
- 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.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.1.0 [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]
- characters 1.2.1
- charts_common 0.12.0 [collection intl logging meta vector_math]
- 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]
- convert 3.1.1 [typed_data]
- 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]
- 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.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_messaging_platform_interface 4.2.16 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.2.17 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- fixnum 1.1.0
- flutter_local_notifications_linux 3.0.0 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories]
- flutter_local_notifications_platform_interface 6.0.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.7 [flutter]
- 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]
- glob 2.1.1 [async collection file path string_scanner]
- google_maps 6.2.0 [js_wrapping meta]
- google_maps_flutter_android 2.4.3 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface stream_transform]
- google_maps_flutter_ios 2.1.13 [flutter google_maps_flutter_platform_interface stream_transform]
- google_maps_flutter_platform_interface 2.2.5 [collection flutter plugin_platform_interface stream_transform]
- graphs 2.2.0 [collection]
- html 0.15.1 [csslib source_span]
- http 0.13.5 [async http_parser meta path]
- http_multi_server 3.2.1 [async]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- io 1.0.4 [meta path string_scanner]
- js 0.6.5 [meta]
- js_wrapping 0.7.4 [js]
- lints 2.0.1
- matcher 0.12.13 [meta stack_trace]
- material_color_utilities 0.2.0
- meta 1.8.0
- mime 1.0.4
- nested 1.0.0 [flutter]
- package_config 2.1.0 [path]
- package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- path 1.8.2
- path_parsing 1.0.1 [vector_math meta]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- 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]
- permission_handler_android 10.2.0 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.0.7 [flutter permission_handler_platform_interface]
- permission_handler_platform_interface 3.9.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.1.2 [flutter permission_handler_platform_interface]
- petitparser 5.1.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.3 [meta]
- 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]
- quiver 3.2.1 [matcher]
- sanitize_html 2.0.0 [html meta]
- shared_preferences_android 2.0.15 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.1.3 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.3 [file flutter path path_provider_linux path_provider_platform_interface 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.3 [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
- source_gen 1.2.7 [analyzer async build dart_style glob path source_span yaml]
- source_helper 1.3.3 [analyzer collection source_gen]
- source_span 1.9.1 [collection path term_glyph]
- stack_trace 1.11.0 [path]
- stream_channel 2.1.1 [async]
- stream_transform 2.1.0
- string_scanner 1.2.0 [source_span]
- 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]
- timing 1.0.1 [json_annotation]
- typed_data 1.3.1 [collection]
- vector_graphics 1.1.4 [flutter vector_graphics_codec]
- vector_graphics_codec 1.1.4
- vector_graphics_compiler 1.1.4 [args meta path_parsing xml vector_graphics_codec]
- vector_math 2.1.4
- video_player_android 2.3.10 [flutter video_player_platform_interface]
- video_player_avfoundation 2.3.8 [flutter video_player_platform_interface]
- video_player_platform_interface 5.1.4 [flutter plugin_platform_interface]
- video_player_web 2.0.13 [flutter flutter_web_plugins video_player_platform_interface]
- watcher 1.0.2 [async path]
- web_socket_channel 2.3.0 [async crypto stream_channel]
- webview_flutter_android 3.2.4 [flutter webview_flutter_platform_interface]
- webview_flutter_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- webview_flutter_wkwebview 3.0.5 [flutter path webview_flutter_platform_interface]
- 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]

@Tom3652
Copy link
Author
Tom3652 commented Mar 25, 2023

Thanks for the explanation @jpears1 i can reproduce now by uninstalling the app using 14.3.0 with the same code :

Capture d’écran 2023-03-25 à 12 41 44

It's working fine indeed using 14.2.5, at least tested on release and debug locally on my phone.

@darshankawar darshankawar added the triage Issue is currently being triaged. label Mar 27, 2023
@darshankawar
Copy link

@Tom3652
Can you take a look at this issue, underlying comments and see if it helps in your case ?

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Mar 27, 2023
@Tom3652
Copy link
Author
Tom3652 commented Mar 27, 2023

Well as mentioned in my comment above, this is working fine using 14.2.5, and i am not sure which comment to look for ? If this is an issue for the ios SDK ?
I am not seeing steps to follow to avoid this unfortunately in the latest version of firebase_messaging

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Mar 27, 2023
@jpears1
Copy link
jpears1 commented Mar 27, 2023

I found out this morning that some messages are being logged that I didn't mention last week because at the the time, my log was filtering out messages not logged directly by my app and I was unaware of that.

When my app calls getToken, the following is being logged by FirebaseMessaging...

10.6.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '44531043044'.Be sure to re-retrieve the FCM token once the APNS device token is set.
10.6.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
    NSLocalizedFailureReason = "No APNS token specified before fetching FCM Token";
}

I looked through #10291, mentioned above darshankawar, and can't say it's the exact same problem, but after reading through it and especially other issues linked to it, it all seems likely related.

#10679 is interesting and talks about changes recently made where an APNS token now needs to be obtained first and then handed off to Firebase before getToken can be called.

No guidance on how that would be done with flutter, or if we should have to worry about it versus it should automatically be dealt with (as I would think) by requestPermission.

I've been able to verify this is all tied to firebase_core 2.8.0 and firebase_messaging 14.3.0. I can consistently reproduce the problem using these versions. If I use previous versions of 2.71 and 14.2.6, I can't reproduce the problem.

I also can make the issue go away by adding an await Future.delayed(500ms) between my app's call to requestPermission and getToken. I also tried a 250ms delay, but the issue still happens. I didn't bother getting into where the threshold is between 250 and 500.

I'm not into adding arbitrary 'sleeps' into our code so, for the moment, I'm changing the pubspec.yaml to revert back to firebase_core 2.7.1 and firebase_messaging 14.2.6.

@darshankawar
Copy link

Thanks for the feedback and details.
I tried to replicate this using the plugin example and latest version of firebase_core and messaging but was unable to replicate it. Keeping this issue open for team's attention and thoughts.

/cc @Lyokone

@darshankawar darshankawar added plugin: messaging platform: ios Issues / PRs which are specifically for iOS. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels Mar 28, 2023
@Lyokone Lyokone self-assigned this Apr 5, 2023
@nurbek-b
Copy link

I found out this morning that some messages are being logged that I didn't mention last week because at the the time, my log was filtering out messages not logged directly by my app and I was unaware of that.

When my app calls getToken, the following is being logged by FirebaseMessaging...

10.6.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '44531043044'.Be sure to re-retrieve the FCM token once the APNS device token is set.
10.6.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
    NSLocalizedFailureReason = "No APNS token specified before fetching FCM Token";
}

I looked through #10291, mentioned above darshankawar, and can't say it's the exact same problem, but after reading through it and especially other issues linked to it, it all seems likely related.

#10679 is interesting and talks about changes recently made where an APNS token now needs to be obtained first and then handed off to Firebase before getToken can be called.

No guidance on how that would be done with flutter, or if we should have to worry about it versus it should automatically be dealt with (as I would think) by requestPermission.

I've been able to verify this is all tied to firebase_core 2.8.0 and firebase_messaging 14.3.0. I can consistently reproduce the problem using these versions. If I use previous versions of 2.71 and 14.2.6, I can't reproduce the problem.

I also can make the issue go away by adding an await Future.delayed(500ms) between my app's call to requestPermission and getToken. I also tried a 250ms delay, but the issue still happens. I didn't bother getting into where the threshold is between 250 and 500.

I'm not into adding arbitrary 'sleeps' into our code so, for the moment, I'm changing the pubspec.yaml to revert back to firebase_core 2.7.1 and firebase_messaging 14.2.6.

I've tried same version as you mentioned core and messaging, but issue still happens. Is there any solutions?

@Jun-Hub
Copy link
Jun-Hub commented May 4, 2023

I have same issue with firebase_core 2.10.0 and firebase_messaging 14.4.1

Only in release build when call FirebaseMessaging.instance.getToken(); before runApp();

@cindyha
Copy link
cindyha commented May 23, 2023

I'm facing same issue in release and profile modes with firebase_core 2.13.0 and firebase_messaging 14.6.1
When call await FirebaseMessaging.instance.getToken() wrapped in try...catch, an error shows [firebase_messaging/unknown] An unknown error has occurred.

I also see this in console logs when the app starts:
10.9.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '556912234891'.Be sure to re-retrieve the FCM token once the APNS device token is set.
10.9.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
NSLocalizedFailureReason = "No APNS token specified before fetching FCM Token";

}

@DukeJeon
Copy link

same issue with firebase_messaging: ^14.6.0 and firebase_core: ^2.12.0

@cindyha
Copy link
cindyha commented May 23, 2023

I'm seeing the same exception being throw by getToken, also firebase_messaging ^14.3.0 (firebase_core: ^2.8.0).

For me, it happens with both debug and release builds.

And it seems to only happen the first time getToken is called after initially installing the app. Subsequent calls to it (such as quitting and then restarting the app) seem to always succeed. Once a token is obtained, if the app deletes the token and then calls getToken again, it succeeds; i..e, truly only seeing it fail on the first getToken attempt after an initial install.

If I go back to an earlier branch of our app's code, that was using firebase_messaging ^14.2.5 (firebase_core: ^2.7.0) then all is OK.

flutter doctor...

flutter pub deps -- --style=compact...

Hei! I have same issue. Did you find any solution for this?

@imcouri
Copy link
imcouri commented May 23, 2023

Im having the same issue when i request the notification token

FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
    NSLocalizedFailureReason = "No APNS token specified before fetching FCM Token";
}
10.9.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '479687329602'.Be sure to re-retrieve the FCM token once the APNS device token is set.
10.9.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified

@dmsrkfcl15
Copy link
dmsrkfcl15 commented May 24, 2023

Same problem with firebase_messaging: ^14.6.1 and firebase_core: ^2.13.0.
The issue seems to be caused by the device requesting a token before obtaining approval related to Apple.
await FirebaseMessaging.instance.requestPermission( alert: true, announcement: false, badge: true, carPlay: false, criticalAlert: false, provisional: false, sound: true, );

It was resolved by adding the 'await' keyword to the code before loading the token.

@noman-hassann
Copy link
noman-hassann commented May 24, 2023

same issue if anyone find solution please mention it
FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
NSLocalizedFailureReason = "No APNS token specified before fetching FCM Token";
} i have tried previous versions also but still getting this issue

@nayanAubie
Copy link

I have the same issue but not getting it every time, the frequency is 1 out of 6 to 7 tries.

@noman-hassann
Copy link
noman-hassann commented May 24, 2023 via email

@nayanAubie
Copy link

@nomi091 What do you mean by flutter cloud configuration? can you explain in brief?

@noman-hassann
Copy link
noman-hassann commented May 24, 2023 via email

@axiftaj
Copy link
axiftaj commented Jun 4, 2023

This works for me, i downgraded the plugins to firebase_core: ^2.7.1 , firebase_messaging: ^14.1.0, repaired caches and run in release mode on my phone from android studio.

It's not working with with firebase_messaging 14.6.2 , firebase_core 2.13.1

But i'm sure this is not the permanent fixed.
@darshankawar

@Speuce
Copy link
Speuce commented Jun 6, 2023

I can confirm this is still an issue with firebase_messaging 14.4.1 and firebase_core 2.10.0.

The fix that worked for me was calling await FirebaseMessaging.instance.requestPermission( alert: true, announcement: false, badge: true, carPlay: false, criticalAlert: false, provisional: false, sound: true); before await FirebaseMessaging.instance.getToken();.

@ashishbeck
Copy link
ashishbeck commented Jun 13, 2023

Along with firebase_core: 2.7.0 and firebase_messaging: 14.2.5, I have found that we need to make sure that the project depends transitively on firebase_core_platform_interface: 4.5.3 by checking the pubspec.lock file. If it doesn't then adding it to pubspec.yaml also solves it. Otherwise, I have experienced this issue #10909

Do we have a timeline on when it will be fixed?

@ayberkcal
Copy link

I have faced same issue. My mistake was I called getToken before permission request. Change order and error fixed. Make sure has permission request completed and accepted before retrive token.

@slice-mohit
Copy link

facing the exact same issue. Getting the error only on testflight. Both debug and release modes work fine if installed from my machine.

@Lyokone
Copy link
Contributor
Lyokone commented Jun 20, 2023

Thanks a lot for all your reports, I'm going to have a look at this issue.

@Lyokone
Copy link
Contributor
Lyokone commented Jun 20, 2023

It seems related to the native SDK, I've opened an issue there: firebase/firebase-ios-sdk#11459

@Punt13140
Copy link

I have the same issue.

I may have found a workaround.
By locking these packages in pubspec.yaml:

  firebase_core: 2.7.1
  firebase_messaging: 14.2.6
  firebase_core_platform_interface: 4.5.3

@cinjon
Copy link
cinjon commented Jun 26, 2023

I am also running into this problem. It consistently happens on first load on a real device, then goes away on second load (and thereafter). It's not a problem in the Simulator.
I would prefer not to lock those packages because then I have to also downgrade Crashlytics.

@majandra2404
Copy link

Hello I am facing the same problem, I would like to know if anyone has got a solution?Please

@Goolpe
Copy link
Goolpe commented Jun 29, 2023

I had the same issue after the dependencies upgrade

10.6.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '44531043044'.Be sure to re-retrieve the FCM token once the APNS device token is set.
10.6.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
    NSLocalizedFailureReason = "No APNS token specified before fetching FCM Token";
}

I had not only Firebase but also another notifications library that needed to override this method in AppDelegate.swift

override func application(
        _ application: UIApplication, 
        didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // third-party library implementation
}

After adding this line to the end of the method, the problem disappeared
return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)

@Lzyct
Copy link
Lzyct commented Jul 3, 2023

I had the same issue after the dependencies upgrade

10.6.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '44531043044'.Be sure to re-retrieve the FCM token once the APNS device token is set.
10.6.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
    NSLocalizedFailureReason = "No APNS token specified before fetching FCM Token";
}

I had not only Firebase but also another notifications library that needed to override this method in AppDelegate.swift

override func application(
        _ application: UIApplication, 
        didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // third-party library implementation
}

After adding this line to the end of the method, the problem disappeared return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)

It's not working on my app,
The app is stuck with white screen

@SkandarClubforce
Copy link

@darshankawar any update on this ?

@darshankawar
Copy link

@SkandarClubforce #10656 (comment)

@Zeinab-Kouhkan
Copy link

I had the same issue on android device.

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: [firebase_messaging/unknown] java.io.IOException: MISSING_INSTANCEID_SERVICE at StandardMethodCodec.decodeEnvelope(message_codecs.dart:653) at MethodChannel._invokeMethod(platform_channel.dart:315) at MethodChannel.invokeMapMethod(platform_channel.dart:518) at MethodChannelFirebaseMessaging.getToken(method_channel_messaging.dart:224)

image

@SkandarClubforce
Copy link

Using old version of firebase fixes things for me:

  firebase_core: '2.7.1'
  firebase_auth: '4.2.10'
  firebase_analytics: '10.1.5'
  firebase_crashlytics: '3.0.16'
  firebase_messaging: '14.2.6'
  cloud_firestore: '4.4.4'
  firebase_core_platform_interface: '4.5.3' # (especially this one)

And in IOS/podfile

pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '10.3.0'

Updating pod file is not necessary, this is just me taking precaution and speed up build times for iOS by downloading the pre-compiled Firestore framework

@baptistesx
Copy link
baptistesx commented Jul 10, 2023

I just had the same issue, i was getting, hopefully then i found that the entitlement was missing in xcode (the capability was already part of the profile)

image

image

@jainmohit2001
Copy link

Any updates on this? @darshankawar @Lyokone.

@SkandarClubforce
Copy link

Logs.

Jul 18 02:55:14 Runner(GoogleUtilities)[39145] <Notice>: 10.10.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
Jul 18 02:55:14 Runner(GoogleUtilities)[39145] <Notice>: 10.10.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID 'XXXXXXXXXXXX'.Be sure to re-retrieve the FCM token once the APNS device token is set.
Jul 18 02:55:14 Runner(GoogleUtilities)[39145] <Notice>: 10.10.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
Jul 18 02:55:14 Runner[39145] <Notice>: FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
    NSLocalizedFailureReason = "No APNS token specified before fetching FCM Token";
}

@pupubird
Copy link
pupubird commented Jul 21, 2023

I managed to resolve it by calling notification permission request from https://pub.dev/packages/permission_handler before requesting the token:

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:permission_handler/permission_handler.dart';
...


  Future<void> setupPushNotification() async {
    await [
      Permission.notification,
    ].request(); // from permission_handler
    NotificationSettings settings = await FirebaseMessaging.instance.requestPermission(
      alert: true,
      badge: true,
      provisional: false,
      sound: true,
    ); // request one more time

    if (settings.authorizationStatus == AuthorizationStatus.authorized) {
      FirebaseMessaging.instance.getToken().then((value) {
        print(value);
      });
    }
  }

@sikandernoori
Copy link

@pupubird are you calling it before runApp or after ?

@mariam-wahba
Copy link

i'm facing same issue and stuck in white screen
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Prefs.init();
await setupLocator();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,);
LocalNotificationService.initialize();
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
NotificationSettings settings = await FirebaseMessaging.instance.requestPermission(alert: true, badge: true, sound: true);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
// print('-------------------------User granted permission');
if (Platform.isIOS) {
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
String? apnsToken = await FirebaseMessaging.instance.getAPNSToken().onError((error, stackTrace) {
print("app is not able to get apsn token: " + error.toString());
});
print("apnsToken: " + apnsToken.toString());
}
await FirebaseMessaging.instance.getToken().then((token){
LoginRequest.deviceToken = token!;
});
print("deviceToken: " + LoginRequest.deviceToken);
FirebaseMessaging.onMessage.listen(_firebaseMessagingForegroundHandler);
FirebaseMessaging.onBackgroundMessage(
_firebaseMessagingBackgroundHandler);
} else {
// print('----------------------------User declined or has not accepted permission');
}
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
xxxxxxxx
});
FirebaseMessaging.instance.getInitialMessage().then((message) {
xxxxxxxxxx
});
runApp(MyApp());
}
Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
xxxxxxx
}
Future _firebaseMessagingForegroundHandler(RemoteMessage message) async {
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(alert: true, badge: true, sound: true);
xxxxxxx
}

import UIKit
import Flutter
import GoogleMaps
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("AIzaSyCFFaOcUnzc0aStuvTcB1xSH-L-mmjVjFY")
FirebaseApp.configure() //add this before the code below
GeneratedPluginRegistrant.register(with: self)
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

in the beginning i was using these
firebase_core: ^2.13.1
firebase_messaging: ^14.6.2
firebase_crashlytics: ^3.3.2
firebase_analytics: ^10.4.2

then downgraded firebase_core: ^2.7.1
firebase_messaging: ^14.2.6
firebase_analytics: ^10.1.5
firebase_crashlytics: ^3.0.16
and added firebase_core_platform_interface: ^4.5.3

still same error [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '461658105137'.Be sure to re-retrieve the FCM token once the APNS device token is set.
FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
NSLocalizedFailureReason = "No APNS token specified before fetching FCM Token";
}
10.12.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
and stuck in white screen

@thaohq-0814
Copy link

I got error when calling this await FirebaseMessaging.instance.deleteToken(). Please someone helps me.
Logs

FLTFirebaseMessaging: An error occurred while calling method Messaging#deleteToken, errorOrNil => {
    NSLocalizedFailureReason = "Invalid unregister response <NSHTTPURLResponse: 0x280a8ea80> { URL: https://fcmtoken.googleapis.com/register } { Status Code: 200, Headers {\n    \"Alt-Svc\" =     (\n        \"h3=\\\":443\\\"; ma=2592000,h3-29=\\\":443\\\"; ma=2592000\"\n    );\n    \"Cache-Control\" =     (\n        \"private, max-age=0\"\n    );\n    \"Content-Encoding\" =     (\n        gzip\n    );\n    \"Content-Length\" =     (\n        40\n    );\n    \"Content-Type\" =     (\n        \"text/plain; charset=UTF-8\"\n    );\n    Date =     (\n        \"Tue, 22 Aug 2023 03:41:20 GMT\"\n    );\n    Expires =     (\n        \"Tue, 22 Aug 2023 03:41:20 GMT\"\n    );\n    Server =     (\n        GSE\n    );\n    \"content-security-policy\" =     (\n        \"frame-ancestors 'self'\"\n    );\n    \"x-content-type-options\" =     (\n        nosniff\n    );\n    \"x-frame-options\" =     (\n        SAMEORIGIN\n    );\n    \"x-xss-protection\" =     (\n        \"1; mode=block\"\n    );\n} }";
}
4
[quic] sec_framer_open_aesgcm failed to open for AESGCM: -4308
[quic] quic_conn_process_inbound [C38.1.1.1:2] [-c867ba3d1a0ecd2e] unable to parse packet

@darshankawar darshankawar added the resolution: fixed A fix has been merged or is pending merge from a PR. label Aug 24, 2023
@firebase firebase locked and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: ios Issues / PRs which are specifically for iOS. plugin: messaging resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.