firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.73k stars 3.98k forks source link

🐛 [firebase_messaging] Get Token Error only in IOS #11439

Closed mariam-wahba closed 1 year ago

mariam-wahba commented 1 year ago

Bug report

Describe the bug It's the same as #9878 and #10656 but happening in release mode only in my TestFlight iOS app. Xcode the latest version Mac oc 13.4 Ventura

Steps to reproduce

Steps to reproduce the behavior:

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

in both times same error and stuck in white screen [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

Expected behavior

the app works and no stuck in white screen

Sample project

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)
}
}

Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [✓] Flutter (Channel stable, 3.10.6, on macOS 13.4 22F66 darwin-x64, locale en-EG) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.3) [✓] Android Studio (version 2022.1) [!] Android Studio ✗ Unable to find bundled Java version. [✓] Connected device (2 available) [✓] Network resources ! Doctor found issues in 1 category. ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 3.0.6 Flutter SDK 3.10.6 myApp 1.0.1+17 dependencies: - build_runner 2.4.6 [analyzer args async 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] - cached_network_image 3.2.3 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - carousel_slider 4.2.1 [flutter] - connectivity_plus 2.3.9 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows] - countup 0.1.4 [flutter] - dio 5.3.2 [async http_parser meta path] - dotted_border 2.0.0+3 [flutter path_drawing] - easy_localization 3.0.2 [flutter shared_preferences intl args path easy_logger flutter_localizations] - easy_localization_loader 1.0.1+1 [http csv yaml xml flutter connectivity_plus path_provider] - file_picker 5.2.10 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path win32] - firebase_analytics 10.4.4 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_core 2.15.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 3.3.4 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_messaging 14.6.5 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine] - flutter_animator 3.2.2 [flutter vector_math] - flutter_cached_pdfview 0.4.2 [flutter flutter_pdfview flutter_cache_manager path_provider path] - flutter_carousel_slider 1.1.0 [flutter] - flutter_cupertino_datetime_picker 3.0.0 [flutter] - flutter_gen_runner 5.3.1 [flutter_gen_core build collection crypto glob path] - flutter_html 3.0.0-beta.2 [html csslib collection list_counter flutter] - flutter_local_notifications 9.9.1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_multi_select_items 0.4.2 [flutter] - flutter_swipe_action_cell 3.1.2 [flutter] - flutter_web_browser 0.17.1 [flutter] - flutter_widget_from_html_core 0.10.3 [csslib flutter fwfh_text_style html] - font_awesome_flutter 10.5.0 [flutter] - full_screen_image_null_safe 2.0.0 [flutter] - geolocator 9.0.2 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows] - get_it 7.6.0 [async collection] - google_maps_flutter 2.4.0 [flutter google_maps_flutter_android google_maps_flutter_ios google_maps_flutter_platform_interface google_maps_flutter_web] - google_maps_flutter_platform_interface 2.4.0 [collection flutter plugin_platform_interface stream_transform] - google_maps_flutter_web 0.5.3 [collection flutter flutter_web_plugins google_maps google_maps_flutter_platform_interface sanitize_html stream_transform] - http 0.13.6 [async http_parser meta] - image_picker 1.0.2 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows] - jiffy 6.2.1 [intl] - linkwell 2.0.6 [flutter url_launcher] - location_permissions 4.0.1 [flutter meta] - mime 1.0.4 - modal_bottom_sheet 2.1.2 [flutter] - multi_select_flutter 4.1.3 [flutter collection] - oktoast 3.3.1 [flutter] - open_file 3.3.2 [flutter ffi] - package_info_plus 3.1.2 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - path_provider 2.0.15 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - percent_indicator 4.2.3 [flutter] - permission_handler 10.4.3 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - permission_handler_platform_interface 3.11.3 [flutter meta plugin_platform_interface] - pod_player_new 0.0.8 [flutter lottie video_player http get wakelock universal_html youtube_explode_dart] - prefs 4.1.0+3 [flutter shared_preferences shared_preferences_web] - rflutter_alert 2.0.7 [flutter] - stop_watch_timer 3.0.1 [flutter rxdart] - syncfusion_flutter_charts 22.2.7 [flutter intl vector_math syncfusion_flutter_core] - url_launcher 6.1.12 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - webviewx 0.2.2 [flutter http path pointer_interceptor uuid webview_flutter] dev dependencies: - 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] dependency overrides: - meta 1.9.1 transitive dependencies: - _fe_analyzer_shared 61.0.0 [meta] - _flutterfire_internals 1.3.4 [collection firebase_core firebase_core_platform_interface flutter meta] - analyzer 5.13.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - archive 3.3.7 [crypto path pointycastle] - args 2.4.2 - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - build 2.4.1 [analyzer async convert crypto glob logging meta package_config path] - build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 4.0.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.2.1 [analyzer async build collection crypto graphs logging package_config path pool pub_semver stream_transform yaml] - build_runner_core 7.2.10 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta package_config path pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.6.1 [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.3.0 - charcode 1.3.1 - checked_yaml 2.0.3 [json_annotation source_span yaml] - clock 1.1.1 - code_builder 4.5.0 [built_collection built_value collection matcher meta] - collection 1.17.1 - color 3.0.0 - connectivity_plus_linux 1.3.1 [flutter connectivity_plus_platform_interface meta nm] - connectivity_plus_macos 1.2.6 [connectivity_plus_platform_interface flutter] - connectivity_plus_platform_interface 1.2.4 [flutter meta plugin_platform_interface] - connectivity_plus_web 1.2.5 [connectivity_plus_platform_interface flutter_web_plugins flutter js] - connectivity_plus_windows 1.2.2 [connectivity_plus_platform_interface flutter] - convert 3.1.1 [typed_data] - cross_file 0.3.3+4 [js meta] - crypto 3.0.3 [typed_data] - csslib 0.17.3 [source_span] - csv 5.0.2 - dart_style 2.3.2 [analyzer args path pub_semver source_span] - dartx 1.2.0 [characters collection crypto meta path time] - dbus 0.7.8 [args ffi meta xml] - easy_logger 0.0.2 [flutter] - fake_async 1.3.1 [clock collection] - ffi 2.0.2 - file 6.1.4 [meta path] - file_selector_linux 0.9.2 [cross_file file_selector_platform_interface flutter] - file_selector_macos 0.9.3+1 [cross_file file_selector_platform_interface flutter] - file_selector_platform_interface 2.6.0 [cross_file flutter http plugin_platform_interface] - file_selector_windows 0.9.3 [cross_file file_selector_platform_interface flutter] - firebase_analytics_platform_interface 3.6.4 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.4+4 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_core_platform_interface 4.8.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.6.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.6.4 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 4.5.4 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.5.4 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - fixnum 1.1.0 - flutter_blurhash 0.7.0 [flutter] - flutter_cache_manager 3.3.1 [clock collection file flutter http path path_provider rxdart sqflite uuid] - flutter_gen_core 5.3.1 [path yaml mime xml dartx color collection json_annotation glob dart_style analyzer args pub_semver source_span] - 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_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math] - flutter_pdfview 1.3.1 [flutter] - flutter_plugin_android_lifecycle 2.0.15 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - freezed_annotation 2.4.1 [collection json_annotation meta] - frontend_server_client 3.2.0 [async path] - fwfh_text_style 2.22.8+3 [flutter logging] - geolocator_android 4.2.2 [flutter geolocator_platform_interface uuid] - geolocator_apple 2.2.7 [flutter geolocator_platform_interface] - geolocator_platform_interface 4.0.7 [flutter plugin_platform_interface vector_math meta] - geolocator_web 2.1.6 [flutter flutter_web_plugins geolocator_platform_interface] - geolocator_windows 0.1.1 [flutter geolocator_platform_interface] - get 4.6.5 [flutter] - glob 2.1.2 [async collection file path string_scanner] - google_maps 6.3.0 [js js_wrapping meta] - google_maps_flutter_android 2.4.15 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface stream_transform] - google_maps_flutter_ios 2.2.3 [flutter google_maps_flutter_platform_interface stream_transform] - graphs 2.3.1 [collection] - html 0.15.4 [csslib source_span] - http_multi_server 3.2.1 [async] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image_picker_android 0.8.7+4 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_for_web 3.0.0 [flutter flutter_web_plugins image_picker_platform_interface mime] - image_picker_ios 0.8.8 [flutter image_picker_platform_interface] - image_picker_linux 0.2.1 [file_selector_linux file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_macos 0.2.1 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_platform_interface 2.9.0 [cross_file flutter http plugin_platform_interface] - image_picker_windows 0.2.1 [file_selector_platform_interface file_selector_windows flutter image_picker_platform_interface] - intl 0.18.0 [clock meta path] - io 1.0.4 [meta path string_scanner] - js 0.6.7 [meta] - js_wrapping 0.7.4 [js] - json_annotation 4.8.1 [meta] - list_counter 1.0.2 - logging 1.2.0 - lottie 2.5.0 [archive flutter path vector_math] - matcher 0.12.15 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.2.0 - nm 0.5.0 [dbus] - octo_image 1.0.2 [flutter flutter_blurhash] - package_config 2.1.0 [path] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.3 - path_drawing 1.0.1 [vector_math meta path_parsing flutter] - path_parsing 1.0.1 [vector_math meta] - path_provider_android 2.1.0 [flutter path_provider_platform_interface] - path_provider_foundation 2.3.0 [flutter path_provider_platform_interface] - path_provider_linux 2.2.0 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.1.0 [flutter platform plugin_platform_interface] - path_provider_windows 2.2.0 [ffi flutter path path_provider_platform_interface win32] - permission_handler_android 10.3.3 [flutter permission_handler_platform_interface] - permission_handler_apple 9.1.4 [flutter permission_handler_platform_interface] - permission_handler_windows 0.1.3 [flutter permission_handler_platform_interface] - petitparser 5.4.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.5 [meta] - pointer_interceptor 0.9.3+4 [flutter] - pointycastle 3.7.3 [collection convert js] - pool 1.5.1 [async stack_trace] - process 4.2.4 [file path platform] - pub_semver 2.1.4 [collection meta] - pubspec_parse 1.2.3 [checked_yaml collection json_annotation pub_semver yaml] - rxdart 0.27.7 - sanitize_html 2.0.0 [html meta] - shared_preferences 2.2.0 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shared_preferences_android 2.2.0 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.3.2 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.3.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.3.0 [flutter plugin_platform_interface] - shared_preferences_web 2.2.0 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.3.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - shelf 1.4.1 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 1.0.4 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_span 1.9.1 [collection path term_glyph] - sqflite 2.3.0 [flutter sqflite_common path] - sqflite_common 2.5.0 [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] - syncfusion_flutter_core 22.2.7 [vector_math flutter] - synchronized 3.1.0 - term_glyph 1.2.1 - test_api 0.5.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - time 2.1.3 [clock] - timezone 0.8.0 [path] - timing 1.0.1 [json_annotation] - typed_data 1.3.2 [collection] - universal_html 2.2.3 [async csslib charcode collection html meta source_span typed_data universal_io] - universal_io 2.2.2 [collection meta typed_data] - url_launcher_android 6.0.37 [flutter url_launcher_platform_interface] - url_launcher_ios 6.1.4 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.5 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.6 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.3 [flutter plugin_platform_interface] - url_launcher_web 2.0.18 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.7 [flutter url_launcher_platform_interface] - uuid 3.0.7 [crypto] - vector_math 2.1.4 - video_player 2.7.0 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web] - video_player_android 2.4.9 [flutter video_player_platform_interface] - video_player_avfoundation 2.4.9 [flutter video_player_platform_interface] - video_player_platform_interface 6.2.0 [flutter plugin_platform_interface] - video_player_web 2.0.16 [flutter flutter_web_plugins video_player_platform_interface] - wakelock 0.6.2 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web wakelock_windows] - wakelock_macos 0.4.0 [flutter flutter_web_plugins wakelock_platform_interface] - wakelock_platform_interface 0.3.0 [flutter meta] - wakelock_web 0.4.0 [flutter flutter_web_plugins js wakelock_platform_interface] - wakelock_windows 0.2.1 [flutter wakelock_platform_interface win32] - watcher 1.1.0 [async path] - web_socket_channel 2.4.0 [async crypto stream_channel] - webview_flutter 2.8.0 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview] - webview_flutter_android 2.10.4 [flutter webview_flutter_platform_interface] - webview_flutter_platform_interface 1.9.5 [flutter meta plugin_platform_interface] - webview_flutter_wkwebview 2.9.5 [flutter path webview_flutter_platform_interface] - win32 3.1.4 [ffi] - xdg_directories 0.2.0+3 [meta path process] - xml 6.3.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] - youtube_explode_dart 1.12.4 [collection freezed_annotation html http http_parser json_annotation meta xml] ```

darshankawar commented 1 year ago

@mariam-wahba I believe you are hitting https://github.com/firebase/flutterfire/issues/10625, so please follow-up in it for further updates. Closing this as a duplicate.

mariam-wahba commented 1 year ago

Hello @darshankawar Do you want more info about my issue? shall i write the in a comment in issue number https://github.com/firebase/flutterfire/issues/10625? is there any work arounds for this issue??

darshankawar commented 1 year ago

shall i write the in a comment in issue number #10625? is there any work arounds for this issue??

Yes, you may share your findings in that issue. Since the root-cause seem to have been identified and team member is assigned to it, you can keep an eye on that issue for fix.