Flutter-Firebase Messaging,Data Messages not received in background and terminated state on ios after killing the app and launching it again

Viewed 588

I am using flutter to develop my app , firebase auth for user authentication and firebase messaging for data notifications when app is in background and terminated state.

In IOS, when app does a fresh firebase authentication and generate a fcm token, notifications are received when app is in background state, but once i kill the app from background , and launch it again , the notifications stop being received by the app until i do a firebase auth verification and generate a new fcm token again.

in main.dart file in the main function initializeFirebase function is 
called .

Future initializeFirebase() async {
  await Firebase.initializeApp();

  FirebaseMessaging.onBackgroundMessage(
    _onAppInTerminatedNotificationHandler, // This Callback must be static
  );

  FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
  FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
}

Future<void> _onAppInTerminatedNotificationHandler(
  RemoteMessage message,
) async {
  //await Firebase.initializeApp();

  print('A new terminated Push Notification Received');
  await NotificationManager.instance.showLocalNotification(message);
}
0 Answers
Related