Flutterfire: [firebase_messaging] onMessage not Triggered when App in Foreground (iOS only)

Created on 10 Feb 2020  路  1Comment  路  Source: FirebaseExtended/flutterfire

Using firebase_messaging 6.0.9 the on message work on Android but not on the iOS.

The device is receiving push notifications when app in background only but when in foreground onMessage didn't triggered.

This is my simple firebase configuration :

_firebaseMessaging.getToken().then((token){
      print("fcm token : " + token);
    });
    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {

        print("on message : $message");
      },
      onResume: (Map<String, dynamic> message) async {
        print("on resume : $message");

      },
      onLaunch: (Map<String, dynamic> message) async {
        print("on launch : $message");

      },
    );
    _firebaseMessaging
        .requestNotificationPermissions(const IosNotificationSettings(
      sound: true,
      alert: true,
      badge: true,
      provisional: true,
    ));
    _firebaseMessaging.onIosSettingsRegistered
        .listen((IosNotificationSettings settings) {
      print("iOS Setting Registered $settings");
    });

bug

Most helpful comment

I've try to remove this code below from my AppDelegate.swift fixed this problem for me :

if #available(iOS 10.0, *) { 
       UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate 
}

I think it's not the best solution, but in this time is oke. Maybe if anyone have another best solution would to share with pleasure.

>All comments

I've try to remove this code below from my AppDelegate.swift fixed this problem for me :

if #available(iOS 10.0, *) { 
       UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate 
}

I think it's not the best solution, but in this time is oke. Maybe if anyone have another best solution would to share with pleasure.

Was this page helpful?
0 / 5 - 0 ratings