firebase / firebase/flutterfire
[firebase_messaging]: `onMessage.listen` is not triggered on MacOS when app is in foreground
- Dominant language
- Dart
- Stars
- 9.3k
- Forks
- 4.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 53
Description
### Is there an existing issue for this?
- [x] 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 :
```dart
Future 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 _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}");
}
```
3. Send a push notification from the server (to the tokens of the MacOS target, not from FCM dashboard)
4. See that you have no log "Message received in app"
### Firebase Core version
3.13.0
### Flutter Version
3.29.3
### Relevant Log Output
```shell
```
### Flutter dependencies
Expand Flutter dependencies snippet
```yaml
Replace this line with the contents of your `flutter pub deps -- --style=compact`.
```
### Additional context and comments
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.