Data are lost after updating ionic app on App Store

I published my ionic application on App Store.

I am storing some data on the mobile phone with Ionic Storage

When I make new release/update on app store when the users update the application the data was lost?

Any idea?

I am using this library:

This is my part of code:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { IonicStorageModule } from "@ionic/storage-angular";
import * as CordovaSQLiteDriver from 'localforage-cordovasqlitedriver';
import { Drivers } from '@ionic/storage';
import { PrivacyConsentModalComponent } from './modals/privacy-consent-modal/privacy-consent-modal.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {FormsModule} from "@angular/forms";

@NgModule({
  declarations: [AppComponent, PrivacyConsentModalComponent],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, HttpClientModule,
    IonicStorageModule.forRoot({
      name: 'mamaDb',
      driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB, Drivers.LocalStorage]
    }),BrowserAnimationsModule,
    FormsModule],
  providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, Toast, ApiService, InternetService, SendMailService, ReadTxtFromFile],
  bootstrap: [AppComponent],
})
export class AppModule { }

Thank you

It looks like you are using SQLite as that is the first driver in the list? Can you confirm that is actually be used on the phone?

Please also share your use of the storage plugin.

What kind of updates did you do between the previous version of the app and your new version?

I know at least with IndexedDB and LocalStorage, if the URL schema changes, the data will be lost as it is stored at the browser/webview level. It is also not guaranteed to stick around as the OS could purge the data from the webview as needed. I have not seen this in our app but we designed it to refresh the data from our backend API if it goes missing. Any critical data like the user’s API key is stored at the native layer.

I am not familiar with the SQLite plugin and where that data is stored.

I am not familiar with sqlLite on ionic as well.

I got the configuration from the documentation (part Adding driver to configuration)

When I deployed my new update on Play Store (for Android) the data are not lost, but when I deployed on App Store (for ios) the data was lost.

I don`t know why.

This is my storage service which I am using:

import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage-angular';
import * as CordovaSQLiteDriver from 'localforage-cordovasqlitedriver';
import { BehaviorSubject, from } from 'rxjs';
import { filter, switchMap } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class StorageService {
  private storageReady = new BehaviorSubject(false);

  constructor(private storage: Storage) {
    this.init();
  }

  async init() {
    await this.storage.defineDriver(CordovaSQLiteDriver);
    await this.storage.create();
    this.storageReady.next(true);
  }

  getData(key: string) {
    return this.storageReady.pipe(
      filter(ready => ready),
      switchMap(o => from(this.storage.get(key) || []))
    );
  }

  addData(key: string, value: any, isArray: boolean = false) {


    return this.storageReady.pipe(
      filter(ready => ready),
      switchMap(async o => {

        const storedData = isArray ? await this.storage.get(key) || [] : value;

        if (isArray) {

          var firstRun = storedData.sort(function (a:any, b:any) {
            return (a.id - b.id);
          });

          value.id = firstRun.length > 0 ? firstRun.reduce((a: number, b: number) => a > b ? a : b).id + 1 : 1;
          storedData.unshift(value);
        }

        await this.storage.set(key, storedData);
        return await this.storage.get(key) || [];
      })
    );
  }

  deleteData(key: string, identifierInArray: any = "", isArray: boolean = false) {
    return this.storageReady.pipe(
      filter(ready => ready),
      switchMap(async o => {
        let elementToRemove = null;
        const resultArr = (await this.storage.get(key));

        if (isArray && identifierInArray) {
          if (!resultArr)
            return;

          elementToRemove = resultArr.find((x: any) => x.id == identifierInArray);
        } else {
          elementToRemove = await this.storage.get(key);
        }

        if (elementToRemove) {
          if (isArray) {
            resultArr.splice(resultArr.indexOf(elementToRemove), 1);
            await this.storage.set(key, resultArr);
          } else {
            await this.storage.remove(key);
          }
        }

        return await this.storage.get(key) || []
      })
    );
  }
}

I made simple changes in html/css , i don`t change anything regarding storing the data.

I made html/css changes and run the command:

ionic cap copy ios
ionic cap open ios

I deployed the app on App Store with xCode from my MacOS Lap Top

Any idea how can I fix it and how can I debug it with out publishing new release on app store?

Thank you