Saturday, June 29, 2024
HomeiOS DevelopmentFlutter - iOS notifications on closed app not correctly receiving

Flutter – iOS notifications on closed app not correctly receiving

[ad_1]

I am making an attempt to obtain notifications on app closed on iOS with firebase_messaging and flutter_local_notifications libraries, if I shut the app (depart it to background) the system receives the notification as regular, additionally stops into the completely different breakpoints, that is why I do know it really works, the issue begins after I shut the app, as I can not see breakpoints anymore I can not test if is correctly working, any recommendation?

Libraries model:

flutter_local_notifications: ^9.4.0

firebase_messaging: ^11.2.5

That is my background message handler on fundamental:

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  // If you are going to use different Firebase providers within the background, resembling Firestore,
  // ensure you name `initializeApp` earlier than utilizing different Firebase providers.
  await Firebase.initializeApp();
  await NotificationService().init();

  print("<PUSH>: Dealing with a background message: ${message.messageId}");
  print('<PUSH>: Message information: ${message.information}');
  print('<PUSH>: Full message: $message');

  if (message.notification != null) {
    print(
        '<PUSH>: Message additionally contained a notification: ${message.notification}');
  }

  if (message.information['errorType'] != null) {
    NotificationService().sendLocalNotification(
      EnumToString.fromString(
          NotificationType.values, message.information['errorType']),
      message.information,
    );
  }
}

Additionally, the executable a part of the fundamental.dart

class RealMain {
  static Future<Widget> getApp({bool testing = false}) async {
    await EasyLocalization.ensureInitialized();

    if (!testing) {
      FirebaseMessaging.onBackgroundMessage(
          _firebaseMessagingBackgroundHandler);

      FirebaseMessaging messaging = FirebaseMessaging.occasion;

      String? token = await messaging.getToken();
      print('<PUSH>: Token: $token');

      messaging.onTokenRefresh.pay attention((String token) {
        print('<PUSH>: Token Refresh: $token');
      });

      FirebaseMessaging.onMessage.pay attention((RemoteMessage message) {
        print('<PUSH>: Bought a message while within the foreground!');
        print('<PUSH>: Message information: ${message.information}');
    

        if (message.notification != null) {
          print(
              '<PUSH>: Message additionally contained a notification: ${message.notification}');
        }

        if (message.information['errorType'] != null) {
          NotificationService().sendLocalNotification(
            EnumToString.fromString(
                NotificationType.values, message.information['errorType']),
            message.information,
          );
        }
      });
      await NotificationService().init();
    }

    return RestartWidget(
      baby: EasyLocalization(
        supportedLocales: GeneralConstants.supportedLocales,
        path: 'lib/app/belongings/localizables',
        fallbackLocale: Locale('en'),
        baby: MyApp(),
      ),
    );
  }
}

Regards.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments