Ad

Flutter Firebase_messaging IOS App Not Receiving Push-up Notifications While App In Foreground

- 1 answer

I'm using flutter with "firebase_messaging 4.0.0+1". Android version is working perfectly. On iOS, if app is in background, notifications work as intended. If app is in foreground, no call to onMessage is made...

_firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) {
    print('on message $message');
  },
  onResume: (Map<String, dynamic> message) {
    print('on resume $message');
  },
  onLaunch: (Map<String, dynamic> message) {
    print('on launch $message');
  },
);

_firebaseMessaging.requestNotificationPermissions(
    const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.getToken().then((token) {
  print('Token: ' + token);
});
Ad

Answer

I also faced similar issue when used stable flutter channel. After I switched to master flutter channel master the issue has gone.

Also it worths mentioning, that there are different payload handlers for Android and iOS.

For a payload:

{
    "to": "<token>",
    "notification": {
        "title": "title_test1",
        "body": "body_test_1"
    },
    "data": {
        "id": "123",
        "event": "test_event"
    }
}

The data handler would be:

    _firebaseMessaging.configure(
        onMessage: (message) {
          if (Platform.isAndroid) {
             print("Android data handler; id: ${message['data']['id']}; event: ${message['data']['event']}");
          } else if (Platform.isIOS) {
             print("iOS data handler; id: ${message['id']}; event: ${message['event']}");
          }
        },
        onLaunch: (message) {
           ...
        },
        onResume: (message) {
           ...
        },
    );
Ad
source: stackoverflow.com
Ad