ionic-team / ionic-storage

Ionic Storage module for Ionic apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to use SQLite for native storage (Android) but only IndexDB and localstorage works ,Error: No available storage method found

MOB-34 opened this issue · comments

commented

AppComponent

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

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    RouterModule.forRoot(
      [],
      { preloadingStrategy: PreloadAllModules }
    ),
    IonicStorageModule.forRoot({
      driverOrder: [
        CordovaSQLiteDriver._driver,
        // Drivers.IndexedDB,
        // Drivers.LocalStorage,
      ],
    }),
  ],
  providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
  bootstrap: [AppComponent],
})
export class AppModule {}

StorageService

import cordovaSQLiteDriver from 'localforage-cordovasqlitedriver';
@Injectable({
  providedIn: 'root',
})
export class StorageService {
  storage$ = concat(
    from(this.ionicStorage.defineDriver(cordovaSQLiteDriver)),
    this.ionicStorage.create()
  ).pipe(
    filter((storage): storage is Storage => !!storage),
    shareReplay(1)
  );
  constructor(private ionicStorage: Storage) {
    this.ionicStorage.defineDriver(cordovaSQLiteDriver).then(() => {
      console.log('defineDriver');
    });
  }
commented

Hey, how did you fix this?
edit: realized 30 minutes later that it doesn't work on web or even android simulator, only on real device

commented

Hey, how did you fix this? edit: realized 30 minutes later that it doesn't work on web or even android simulator, only on real device

@puddinator https://github.com/MOB-34/ion-storage.git hope it would help you out