ionic-team / ionic-storage

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

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

Closed MOB-34 closed 1 year ago

MOB-34 commented 1 year ago

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');
    });
  }
puddinator commented 1 year ago

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

MOB-34 commented 1 year ago

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