ionic-team / ionic-storage

Ionic Storage module for Ionic apps
MIT License
437 stars 99 forks source link

IOS app doesn't retain state after ionic/storage version(3.0.6) upgrade for ionic app #282

Open kharakAdhikari opened 1 year ago

kharakAdhikari commented 1 year ago

Hi team, I recently upgraded ionic storage from V2.2.0 to V3.0.6 in an ionic app. I'm facing IOS specific issue after the upgrade, IOS app doesn't retain login credentials after app kill which was retaining in ionic/storage(2.2.0) . Could you please help me to understand what I’m missing here ?

Code snippet after the upgrade:

import { IonicStorageModule } from '@ionic/storage-angular';
import { Drivers } from '@ionic/storage';
import * as CordovaSQLiteDriver from 'localforage-cordovasqlitedriver';
import { Storage } from '@ionic/storage-angular';

@NgModule({
  imports: [
    IonicStorageModule.forRoot({
      driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB, Drivers.LocalStorage]
    })
  ]})

These are my env versions:

   Ionic CLI                     : 6.20.6
   Ionic Framework               : @ionic/angular 6.2.1
   @angular-devkit/build-angular : 13.3.10
   @angular-devkit/schematics    : 13.3.10
   @angular/cli                  : 13.1.2
   @ionic/angular-toolkit        : 6.1.0
   @ionic/storage-angular        : 3.0.6
   @ionic/angular                : 6.2.1

Code Before upgrade

getState(): Promise<{}> {
    return this.storage.ready().then(() => {
      return this.storage
        .get(this.syncKey)
        .then(s => s || {})
        .catch(err => {
           console.log(‘something wrong’)
          return Promise.resolve({});
        });
    });
  }



Code after upgrade:

getState(): Promise<{}> {
    return this.storage.create().then(() => {
      return this.storage
        .get(this.syncKey)
        .then(s => s || {})
        .catch(err => {
           console.log(‘something wrong’)
          return Promise.resolve({});
        });
    });
  }

Important: I’ve injected Storage service in multiple custom services, I replaced this.storage.ready() with this.storage.create() after the upgrade. Just curious to know if I’ve multiple occurrences of this.storage.ready() in a custom service and if I replace it with this.storage.create(), does it create a new instance every time getState() gets called ?

YanouonaY commented 10 months ago

Hello, @kharakAdhikari did you find the solution?