Skip to content

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

Open
@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

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

    Issue actions