title: Flutter didChangeAppLifecycleState stopped working in iOS
body: <p>Please help!!!</p>
  <p>Here is a sample of my code (only important parts extracted)</p>
  <pre><code>  @override
    void didChangeAppLifecycleState(AppLifecycleState state) {
      super.didChangeAppLifecycleState(state);
      switch (state) {
        case AppLifecycleState.paused: 
         AuraPreferences.queryPreference('AppointmentRemindMe').then((value) async {
            if (appState.isUserLoggedIn &amp;&amp; AuraConvert.toBoolean(value)) {
              // stop foreground and resume background appointment reminders
              AppointmentReminder.stop();
              await AppointmentReminder.scheduleRemindersInBackground();
            }
          });
  
          ProgressNoteService.stop();
          chatMessageProvider.stopConnection();
  
          _goneToBackgroundAt = DateTime.now().toUtc();
  
          appState.cancelSsoTimer();
  
          print('App went to background at $_goneToBackgroundAt');
          break;
  
        case AppLifecycleState.resumed:
  </code></pre>
  <hr />
  <pre><code>  static Future&lt;void&gt; scheduleRemindersInBackground() async {
      // schedule appointment reminders in background 10 minutes before they are supposed to occur
      final appointments = await ScheduleService.getAppointmentReminders(inNextMinutes: 60 * 24 * 3);
      for (int i = 0; i &lt; appointments.length; i++) {
        await _scheduleReminderInBackground(
  </code></pre>
  <hr />
  <pre><code>  static Future&lt;List&lt;AuraAppointment&gt;&gt; getAppointmentReminders({required int inNextMinutes}) async {
      var now = DateTime.now();
      now = DateTime(now.year, now.month, now.day, now.hour, now.minute);
      final to = now.add(Duration(minutes: inNextMinutes));
  
      if (cacheAppointments.containsKey(DateTimeRange(start: now, end: to))) {
        return cacheAppointments[DateTimeRange(start: now, end: to)] ?? &lt;AuraAppointment&gt;[];
      }
  
      var appointments = await getAppointments(now, to);
  </code></pre>
  <hr />
  <pre><code>class ScheduleService {
    static Future&lt;List&lt;AuraAppointment&gt;&gt; getAppointments(
      DateTime? dateFrom,
      DateTime? dateTo, {
      isCalledFromCalendar = false,
      isSync = false,
    }) async {
      if (dateFrom == null || dateTo == null) return &lt;AuraAppointment&gt;[];
  
      final authUser = await UserService.authUser;
  
         final String uri = 'https://api.domain123.com/something_here_to_send_parameters';
  
      final networkHelper = NetworkHelper(uri, authUser: authUser, goToLoginScreen: isCalledFromCalendar);
  
      var appointments = await networkHelper.get&lt;List&lt;AuraAppointment&gt;&gt;((dynamic data) {
        return (data as List).map((i) =&gt; AuraAppointment.fromMap(i)).toList();
      });
  
      final localDb = await MobileDatabase.dbInstance;
  
      if (NetworkHelper.isConnected) {
        if (appointments == null) return &lt;AuraAppointment&gt;[];
  
        if (isSync) {
          await MobileDatabase.deleteData('AuraAppointments', {'OwnerID': authUser?.userId});
        }
  
        // upsert data into local database to be available in off-line mode
        for (var appointment in appointments) {
          appointment.ownerId = authUser?.userId;
          MobileDatabase.upsertData('AuraAppointments', appointment.toMap());
        }
      } else {
        appointments = (await localDb.query(
          'AuraAppointments',
          where: 'OwnerID = ?',
          whereArgs: [authUser?.userId],
        ))
            .map((i) =&gt; AuraAppointment.fromMap(i))
            .toList();
      }
  
      final individualApp = appointments.where((a) =&gt; a.scgrID == 0);
      individualApp.forEach((ia) {
        if (ia.clientID != null &amp;&amp; ia.clientID! &gt; 0) ia.clientIDs.add(ia.clientID);
      });
  
      final groupApp = appointments.where((a) =&gt; a.scgrID! &gt; 0 &amp;&amp; a.clientID == 0);
      groupApp.forEach((ga) {
        final clients =
            appointments!.where((a) =&gt; a.scgrID == ga.scgrID &amp;&amp; a.clientID! &gt; 0).map((a) =&gt; a.clientID).toList();
        ga.clientIDs.addAll(clients);
      });
  
      var resultApp = &lt;AuraAppointment&gt;[];
      resultApp.addAll(individualApp);
      resultApp.addAll(groupApp);
  
      return resultApp;
    } // end of getAppointments method
  </code></pre>
  <hr />
  <p>The notifications works correctly when the app is in the offline mode but doesn't work when it is in online mode. The appointments (data) come from local DB in offline mode and web API in online mode. It means that web API fails when it is called at the time when the app is pushed to the background. This happens only in release builds for iOS (Android is good) but not in debug builds when I run the code on my iPhone 8 device.
  PLEASE HELP ME SOLVE THIS PROBLEM!!!</p>
  <p>Doctor summary (to see all details, run flutter doctor -v):</p>
  <p>Flutter (Channel stable, 2.2.3, on Mac OS X 10.15.7 19H524 darwin-x64, locale en-CA)</p>
  <p>Android toolchain - develop for Android devices (Android SDK version 30.0.2)</p>
  <p>Android Studio (version 4.2)</p>
  <p>iOS version is 14.4</p>