Skip to content

[firebase_messaging]: FirebaseMessaging.instance.getInitialMessage() is always null on iOS after upgrade to 15.2.2 #17107

@lukyanov

Description

@lukyanov

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Messaging

Which platforms are affected?

iOS

Description

await FirebaseMessaging.instance.getInitialMessage() is always null when the app is opened from the "killed" state.

The plugin version 15.1.6 (the previous version I used) worked as expected.

iOS 18.3.1

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
  RemoteMessage? initialMessage = await FirebaseMessaging.instance.getInitialMessage()
  // initialMessage is always null here
}

void main() async {
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  ...
}

Reproducing the issue

  1. Close the app (swipe it away)
  2. Send a notification via firebase console or with a script (in my case I have a link attached to the notification data)
  3. Tap the notification
  4. Observe initialMessage being null

Firebase Core version

3.11.0

Flutter Version

3.27.2

Relevant Log Output

Flutter dependencies

No response

Additional context and comments

No response

Activity

SelaseKay

SelaseKay commented on Feb 17, 2025

@SelaseKay
Contributor

Hi @lukyanov, I've been able to reproduce this issue with the firebase_messaging example app. As a workaround, add a delay of 3 seconds before calling getInitialMessage and see if it resolves your issue.

added
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
and removed
Needs AttentionThis issue needs maintainer attention.
on Feb 17, 2025
google-oss-bot

google-oss-bot commented on Feb 26, 2025

@google-oss-bot

Hey @lukyanov. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

austinwitherspoon

austinwitherspoon commented on Mar 1, 2025

@austinwitherspoon

A portion of users of my app on android have been hitting this issue suddenly over the past few weeks. Not sure if there was an android update that broke it, but for the affected users now every RemoteMessage ends up filled with null values.

fahmisdk6

fahmisdk6 commented on Mar 10, 2025

@fahmisdk6

I observe a similar issue on Android, will this issue be resolved?

Kamuel09

Kamuel09 commented on Mar 13, 2025

@Kamuel09

I’m not sure if this will be a hint, but when the RemoteMessage of getInitialMessage() is null, onMessage.listen does not work in the foreground state. However, when the RemoteMessage of getInitialMessage() is not null, onMessage.listen works in the foreground state.

The test was conducted on the Galaxy S25 Ultra, and normal operation was confirmed on the Galaxy Note 10 Plus and Galaxy S22.

pranil-key

pranil-key commented on Mar 17, 2025

@pranil-key

facing same issue

18 remaining items

MichaelVerdon

MichaelVerdon commented on May 23, 2025

@MichaelVerdon
Contributor

Hey there @lukyanov does @lirunghi261 solution work for you?

added
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
and removed
Needs AttentionThis issue needs maintainer attention.
on May 23, 2025
lukyanov

lukyanov commented on Jun 3, 2025

@lukyanov
Author

Hey there @lukyanov does @lirunghi261 solution work for you?

Well, maybe, I don't know. My initial issue was about the official firebase messaging plugin, not about custom workarounds. So I'm not sure I understand the question. Shouldn't the solution be a part of the plugin itself? Will you just close the issue if the custom workaround works? I'm a bit surprised to be honest.

added
Needs AttentionThis issue needs maintainer attention.
and removed
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
on Jun 3, 2025
lukyanov

lukyanov commented on Jun 3, 2025

@lukyanov
Author

It's been more than 3 months from the upgrade (from 15.1.6 to 15.2.2) that broke the behaviour the plugin officially states in its documentation.

SelaseKay

SelaseKay commented on Jun 12, 2025

@SelaseKay
Contributor

Hi @lukyanov, you mentioned that it works fine on version 15.1.6, but I'm still able to reproduce the issue on that version. Could you confirm if that version still working as expected for you?

added
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
and removed
Needs AttentionThis issue needs maintainer attention.
on Jun 12, 2025
WillowWisp

WillowWisp commented on Jun 13, 2025

@WillowWisp

It's been more than 3 months from the upgrade (from 15.1.6 to 15.2.2) that broke the behaviour the plugin officially states in its documentation.

I cannot even use version 15.1.6 as a temporary workaround because of this issue: #16670

May I ask your firebase_core and firebase_messaging versions?

newengine

newengine commented on Jun 24, 2025

@newengine

I experienced the same issue, any update?
firebase_messaging: ^15.1.6
firebase_core: ^3.12.1

added
Needs AttentionThis issue needs maintainer attention.
and removed
blocked: customer-responseWaiting for customer response, e.g. more information was requested.
on Jun 26, 2025
russellwheatley

russellwheatley commented on Jul 17, 2025

@russellwheatley
Member

Hi @lukyanov - I have had a look into this issue. I'm a bit confused really, the code snippet you provided:

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
  RemoteMessage? initialMessage = await FirebaseMessaging.instance.getInitialMessage()
  // initialMessage is always null here
}

does indeed return a null initialMessage, but I would expect it to because the background message handler fires largely before the user has a chance to tap the notification and open the app from a terminated state.

However, if I open the app with a notification, and then attempt to retrieve the initialMessage via this button: https://github.com/firebase/flutterfire/blob/main/packages/firebase_messaging/firebase_messaging/example/lib/main.dart#L327

I can retrieve the initialMessage without issue.

I am aware of another issue that might occur; I believe this AppDelegate call handler which retrieves initial message: https://github.com/firebase/flutterfire/blob/main/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m#L214

Might not have been called before there is a chance to get the initial message via getInitialMessage() which is why a delay has been suggested to be 100% sure it has fired.

I took a look at the code diff between latest version and the last version you suggested getInitialMessage() was working for iOS plugin code: https://github.com/firebase/flutterfire/blob/main/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m

This is the only PR I could find that changes that file: https://github.com/firebase/flutterfire/pull/13484/files

I don't think this should effect the handling of initial messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lukyanov@fahmisdk6@russellwheatley@newengine@google-oss-bot

        Issue actions

          [firebase_messaging]: FirebaseMessaging.instance.getInitialMessage() is always null on iOS after upgrade to 15.2.2 · Issue #17107 · firebase/flutterfire