Skip to content

[firebase_messaging]: onMessage.listen is not triggered on MacOS when app is in foreground #17339

@Tom3652

Description

@Tom3652

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Messaging

Which platforms are affected?

macOS

Description

This code :

FirebaseMessaging.onMessage.listen((RemoteMessage event) {
  print("Message received in app : ${event.toMap()}");
  });

Seems to not log anything when receiving a Push notification when the app is in the foreground on MacOS.
It works fine on Android / iOS but not on my Mac (on the same app with the same server code sending the same push notification)

Reproducing the issue

  1. Create a sample app or use the plugin example if it allows it
  2. Use this code :
 Future<void> initialize() async {
    NotificationSettings settings = await FirebaseMessaging.instance
        .requestPermission(sound: true, carPlay: true);

    if (settings.authorizationStatus == AuthorizationStatus.authorized ||
        settings.authorizationStatus == AuthorizationStatus.provisional) {
      _getToken();

      print("Initializing the message listener...");
      FirebaseMessaging.onMessage.listen((RemoteMessage event) {
        print("Message received in app : ${event.toMap()}");
        });
    } 
  }


 Future<void> _getToken() async {
        String? apnsToken = await FirebaseMessaging.instance.getAPNSToken();
       print("APNS Token : $apnsToken on ${Platform.operatingSystem}");
      String token = await FirebaseMessaging.instance.getToken() ?? "";
      print("FCM Token : $token on ${Platform.operatingSystem}");
    }
  1. Send a push notification from the server (to the tokens of the MacOS target, not from FCM dashboard)
  2. See that you have no log "Message received in app"

Firebase Core version

3.13.0

Flutter Version

3.29.3

Relevant Log Output

Flutter dependencies

Expand Flutter dependencies snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.

Additional context and comments

No response

Activity

Tom3652

Tom3652 commented on May 9, 2025

@Tom3652
Author

I will try with the example project as soon as i can to confirm it is an issue.
Edit : i have tried but it's quite complicated to run with xcode profiles in error...

SelaseKay

SelaseKay commented on May 9, 2025

@SelaseKay
Contributor

Hi @Tom3652, thanks for the report. I was able to reproduce this issue with the firebase_messaging example app. We'll investigate further.

SelaseKay

SelaseKay commented on May 12, 2025

@SelaseKay
Contributor

Hi @Tom3652, after subsequent tests, I observed that onMessage is eventually called but after a significant delay, which seems very unusual. Could you please check if you're experiencing the same behavior on your end?

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

Tom3652 commented on May 12, 2025

@Tom3652
Author

Hi @SelaseKay , yes indeed !

I thought it was never called but i guess it's because the delay is too long and i was closing the app. But i have observed what you have described as well, we are talking about few minutes here not seconds 🙏

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

SelaseKay commented on Jun 12, 2025

@SelaseKay
Contributor

Hi @Tom3652, I did a bit of digging and came across this thread: https://developer.apple.com/forums/thread/740923. It seems the issue goes beyond firebase_messaging plugin.

Tom3652

Tom3652 commented on Jun 13, 2025

@Tom3652
Author

Hi @SelaseKay !

Yes it may be right, but how should we proceed then ?
Should i raise a firebase support ticket explaining that to see if they are aware of such situation and will confirm that this is not a firebase issue ?

It is weird because it seems it was working last year for me (my Mac was always up to date at any time so i was on Mac Os versions that should have experienced this issue)

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

        @google-oss-bot@Tom3652@SelaseKay

        Issue actions

          [firebase_messaging]: `onMessage.listen` is not triggered on MacOS when app is in foreground · Issue #17339 · firebase/flutterfire