flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_messaging]: getInitialMessage hangs indefinitely

Open passsionforprogramming opened this issue 1 month ago • 15 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues.

Which plugins are affected?

Messaging

Which platforms are affected?

iOS

Description

When calling FirebaseMessaging.instance.getInitialMessage the call hangs indefinitely

Reproducing the issue

Call FirebaseMessaging.instance.getInitialMessage() with version ^16.0.4 and flutter version 3.38.1

Firebase Core version

4.2.1

Flutter Version

3.38.1

Relevant Log Output


Flutter dependencies

Expand Flutter dependencies snippet

  cupertino_icons: ^1.0.8
  animated_widgets: ^1.1.0
  firebase_analytics: ^12.0.4
  popover: ^0.3.1
  rxdart: ^0.28.0
  http: ^1.5.0
  country_code_picker: ^3.0.0
  firebase_auth: ^6.1.2
  firebase_core: ^4.2.1
  another_flushbar: ^1.12.30
  flutter_facebook_auth: ^7.1.2
  flutter_spinkit: ^5.2.1
  loading_animations: ^2.2.0
  retrofit: ^4.7.1
  json_annotation:
  json_serializable: ^6.10.0
  dio: ^5.9.0
  dio_http_cache_lts: ^0.4.1
  connectivity_plus: ^6.1.5
  shared_preferences: ^2.0.5
  pin_code_fields: ^8.0.1
  phone_numbers_parser: ^9.0.3
  image_picker: ^1.2.0
  image_cropper: ^9.1.0
  firebase_storage: ^13.0.4
  intl: ^0.18.1
  country_state_city_picker: ^1.2.8
  awesome_dialog: ^3.2.1
  adaptive_action_sheet: ^2.0.4
  file_picker: ^10.3.2
  fast_contacts: ^4.0.0
  permission_handler: ^12.0.1
  flutter_countdown_timer: ^4.1.0
  chewie: ^1.13.0
  timeago: ^3.7.1
  video_player: ^2.10.0
  confetti: ^0.8.0
  path_provider: ^2.1.4
  get_time_ago:
  pull_to_refresh: ^2.0.0
  omni_datetime_picker: ^2.0.5
  flutter_tags_x: ^1.1.0
  grouped_list:
  emoji_picker_flutter: ^4.3.0
  carousel_slider: ^5.1.1
  in_app_purchase: ^3.2.3
  in_app_purchase_storekit: 0.4.4
  cloud_firestore: ^6.0.3
  # firebase
#  video_compress: ^3.1.0
  provider: ^6.1.2
  cached_network_image: ^3.4.1
  font_awesome_flutter: ^10.7.0
  flutter_svg: ^2.0.7
  image: ^4.3.0
#  video_trimmer: ^2.1.0
  uuid: ^4.4.2
  googleapis_auth: ^1.6.0
  background_downloader: ^9.2.6
  googleapis: ^11.2.0
  flutter_local_notifications: ^19.5.0
  gcloud: ^0.8.5
  mime_type: ^1.0.0
  percent_indicator: ^4.2.2
  hive_ce: ^2.12.0
  hive_ce_flutter: ^2.3.2
  page_transition: ^2.0.4
  modal_progress_hud_nsn: ^0.5.1
  flutter_typeahead: ^5.2.0
  image_cropping: ^0.0.9
  firebase_messaging: ^16.0.4
  webview_flutter: ^4.8.0
  marquee: ^2.3.0
  share_plus: ^12.0.1
  nb_utils: ^7.1.7+2
  flutter_staggered_grid_view: ^0.7.0
  photo_view: ^0.15.0
  # full is for android
#  ffmpeg_kit_flutter_full: ^6.0.3-LTS
#  ffmpeg_kit_flutter_full_gpl: ^6.0.3-LTS
  flutter_svg_provider: ^1.0.7
#  agora_rtc_engine: ^6.3.2
  google_sign_in: ^7.1.1
#  firebase_app_check: ^0.3.1+3
  firebase_crashlytics: ^5.0.4
  firebase_in_app_messaging: ^0.9.0+4
  watcher: ^1.1.0
  memory_info: ^0.0.3
  go_router: ^17.0.0
  google_fonts: ^6.3.0
  sign_in_with_apple: ^7.0.1
  webview_flutter_plus: ^0.4.5
  url_launcher: ^6.3.2
  audioplayers: ^6.5.0
  dotted_border: ^3.1.0
#  tflite_flutter_helper: ^0.3.1
  tflite_flutter: ^0.11.0
#  tflite_flutter_helper_plus: ^0.0.2
#  tflite_flutter_helper_plus: ^0.0.2
#  agora_rtc_engine: 5.2.0
#  shelf: ^1.4.1
#  shelf_static: ^1.1.2
#  shelf_cors_headers: ^0.1.5
  flutter_inappwebview: ^6.0.0
  package_info_plus: ^8.0.2
  sliver_tools: ^0.2.12
  in_app_review: ^2.0.10
  cupertino_back_gesture: ^0.1.0
  crypto: ^3.0.6
  mime: any
  path: any
  in_app_purchase_android: any
  upgrader: ^11.5.0
  video_compress: ^3.1.4
  tutorial_coach_mark: ^1.3.3
  video_player_android: ^2.7.17
#  media_kit_libs_android_video: any
#  video_player_media_kit: ^1.0.5
  device_info_plus: ^11.3.0
  youtube_player_flutter: ^9.1.1
  better_player_plus: ^1.0.8
  flutter_video_caching: ^0.4.4

Additional context and comments

No response

passsionforprogramming avatar Nov 16 '25 13:11 passsionforprogramming

Hi @passsionforprogramming, kindly share a reproducible example for this issue.

SelaseKay avatar Nov 17 '25 09:11 SelaseKay

I can confirm this is happening in our apps too.

I first encountered it with the same versions as initially reported, but tried to downgrade a bit with:

  • Flutter 3.38.2
  • firebase_core: 4.2.1
  • firebase_messaging: 16.0.0

and the bug was still happening.

vincent-hoodoo avatar Nov 19 '25 03:11 vincent-hoodoo

Hi @passsionforprogramming, @vincent-hoodoo, have you migrated your app to use UISceneDelegate per this documentation? I suspect that could be the issue.

SelaseKay avatar Nov 20 '25 14:11 SelaseKay

I am also seeing this issue and yes, I have migrated to UISceneDelegate.

mtallenca avatar Nov 20 '25 17:11 mtallenca

I confirm this is due to the UISceneDelegate Migration. Even the streams aren't working on iOS side after migrating to it.

I rolled back the migration and everything is working fine.

override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    let googleApiKey = Bundle.main.object(forInfoDictionaryKey: "GOOGLE_API_KEY") as! String
    GMSServices.provideAPIKey(googleApiKey)

    FirebaseApp.configure()

    UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
   
    application.registerForRemoteNotifications() //Probably the cause of our pain.

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

martinhellocse avatar Nov 20 '25 17:11 martinhellocse

Yes we migrated our apps to UISceneDelegate .

vincent-hoodoo avatar Nov 20 '25 20:11 vincent-hoodoo

Can someone please remove the tag blocked: customer-response manually before the bot auto-closes this issue, original author does not seem to using Github regularly and there are many of us are confirming the cause of the issue is migration to UISceneDelegate.

kishan-dhankecha avatar Nov 29 '25 07:11 kishan-dhankecha

Hi all, I've created a PR for this. Can you test against branch name messaging_17859 and confirm if this resolves the issue?

  firebase_messaging:
      git:
        url: https://github.com/firebase/flutterfire.git
        ref: messaging_17859
        path: packages/firebase_messaging/firebase_messaging

SelaseKay avatar Dec 03 '25 11:12 SelaseKay

Hi @SelaseKay, we encountered the same issue in our project, and using the messaging_17859 branch resolved it on our end

MPinto16 avatar Dec 04 '25 12:12 MPinto16

Hi @MPinto16, thanks for confirming. Can anyone else confirm if this PR resolves the issue?

SelaseKay avatar Dec 04 '25 13:12 SelaseKay

Hi @MPinto16, thanks for confirming. Can anyone else confirm if this PR resolves the issue?

I tried with your PR and this delegate and still hanging:

@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    // Google Maps SDK configuration
    if let googleMapsAPIKey = Bundle.main.infoDictionary?["GoogleMapsAPIKey"] as? String {
        GMSServices.provideAPIKey(googleMapsAPIKey)
    }

    FirebaseApp.configure()

    
    UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
      
    application.registerForRemoteNotifications()

    // Background process
    // Note: this is a minimum time interval, there's no guarantee on how often this will be called.
    UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)


    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
    func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
      GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
    }
    
}

If you need more info i'm glad to help you with anything

FreeXeeD avatar Dec 04 '25 15:12 FreeXeeD

@SelaseKay using your PR, I now get the APNS Token, but getInitialMessage still hangs indefinitely

peter-bishay avatar Dec 05 '25 04:12 peter-bishay

Hi @passsionforprogramming, @vincent-hoodoo, have you migrated your app to use UISceneDelegate per this documentation? I suspect that could be the issue.

Hello, yes I have migrated.

passsionforprogramming avatar Dec 06 '25 20:12 passsionforprogramming

Same issue here, any quick fix to resolve this? I tried with your PR @SelaseKay and getInitialMessage hangs indefinitely

emisanpre avatar Dec 09 '25 23:12 emisanpre

When trying to login via sms this happens @SelaseKay

FirebaseAuthException ([firebase_auth/notification-not-forwarded] 
If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need tobe forwarded to FirebaseAuth's canHandleNotification method.)`

Issue related with notifications

emisanpre avatar Dec 10 '25 00:12 emisanpre

Hi all, I've created a PR for this. Kindly test against this branch(fix-messaging-callbacks-uiscene) and confirm if this resolves the issue.

  firebase_messaging:
      git:
        url: https://github.com/firebase/flutterfire.git
        ref: fix-messaging-callbacks-uiscene
        path: packages/firebase_messaging/firebase_messaging

SelaseKay avatar Dec 11 '25 12:12 SelaseKay

Will this fix the Stream issue also? Because as of now FirebaseMessaging.onMessage also not working for me

kishan-dhankecha avatar Dec 11 '25 12:12 kishan-dhankecha

I can confirm that using this branch does solve FirebaseMessaging.onMessage issue and also getInitialMessage is not hanging indefinitely now. 🎉

kishan-dhankecha avatar Dec 11 '25 13:12 kishan-dhankecha