HomeiOS DevelopmentHow or the place to retailer FCM Background notification knowledge in Hive...

How or the place to retailer FCM Background notification knowledge in Hive in Flutter iOS?


  1. Each ios and AOS obtain background notification usually.
  2. In AOS, acquired background notification knowledge could be saved in Hive by backgroundHandler.
  3. However in ios BackgroundHander would not work.
  4. If BackgroundHandler shouldn’t be supported on iOS, is there one other means?
  5. Is it not potential to save lots of background notification knowledge to Hive in iOS?

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp(
    choices: DefaultFirebaseOptions.currentPlatform,
  );
  if (!Hive.isAdapterRegistered(1)) {
    Hive.registerAdapter<PushNotificationModel>(PushNotificationModelAdapter());
  }

  ultimate documentDirectory = await getApplicationDocumentsDirectory();
  Hive.init(documentDirectory.path);
  if (Hive.isBoxOpen(HiveBoxConstant.BACKGROUND_NOTIFICATION_LIST)) {
    await Hive.field<PushNotificationModel>(HiveBoxConstant.BACKGROUND_NOTIFICATION_LIST).shut();
  }
  if (Hive.isBoxOpen(HiveBoxConstant.NOTIFICATION_LIST)) {
    await Hive.field<PushNotificationModel>(HiveBoxConstant.NOTIFICATION_LIST).shut();
  }
  await Hive.openBox<PushNotificationModel>(HiveBoxConstant.BACKGROUND_NOTIFICATION_LIST);
  await Hive.openBox<PushNotificationModel>(HiveBoxConstant.NOTIFICATION_LIST);

  await FCMManager.saveNotificationList(message, true);

  if (Hive.isBoxOpen(HiveBoxConstant.BACKGROUND_NOTIFICATION_LIST)) {
    await Hive.field<PushNotificationModel>(HiveBoxConstant.BACKGROUND_NOTIFICATION_LIST).shut();
  }
  if (Hive.isBoxOpen(HiveBoxConstant.NOTIFICATION_LIST)) {
    await Hive.field<PushNotificationModel>(HiveBoxConstant.NOTIFICATION_LIST).shut();
  }
}

void essential() async {
  WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();

...

  await Firebase.initializeApp(choices: DefaultFirebaseOptions.currentPlatform);


  runApp(
  ...
  );
}

ultimate GlobalKey<NavigatorState> navigatorStateGlobalKey = GlobalKey<NavigatorState>();

class AppMain extends ConsumerStatefulWidget {
  const AppMain({Key? key}) : tremendous(key: key);

  @override
  ConsumerState<AppMain> createState() => _AppMainState();
}

class _AppMainState extends ConsumerState<AppMain> with WidgetsBindingObserver {


  @override
  void initState() {
    tremendous.initState();

    FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  }

  @override
  Widget construct(BuildContext context) {
    return MaterialApp(
      ...
    );
  }

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments