Monday, October 23, 2023
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, obtained background notification knowledge could be saved in Hive by means of backgroundHandler.
  3. However in ios BackgroundHander would not work.
  4. If BackgroundHandler isn’t supported on iOS, is there one other approach?
  5. Is it not doable 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());
  }

  last 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(
  ...
  );
}

last 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(
      ...
    );
  }

}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments