Problem with IonicStorage

I am using IonicStorage to save personalised data. I have a provider which is as follows:

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

import { Storage } from '@ionic/storage';

@Injectable()
export class UserProvider {

  info: Info;
  settings: Settings;
  Defaults: {settings: Settings, info: Info};

  constructor(public http: Http, private storage: Storage ) {

    console.log('UserProvider Initialisation Started...');

    this.Defaults = {
      settings: {
        Notifications: true,
        AppTheme: 'primary'
      },
      info: null
    };

    this.info = this.Defaults.info;
    this.settings = this.Defaults.settings;

    // ---------------------------------------------
    // Call Api for data and init into local storage
    // ---------------------------------------------

    this.initSettings();

  }

  initSettings() {
    this.storage.get('userSettings').then((val) => {
      // console.log(`UserInfo ${val}`);
      if (val == null) {
        console.log('Found val for userSettings.color null');
        this.storage.set('userSettings', JSON.stringify(this.settings));
      }
      else {
        this.settings = JSON.parse(val);
      }
    });
  }

  getInfo(): Info {
    return this.info;
  }

  getSettings(): Settings {
    // console.log(`this.settings-> ${JSON.stringify(this.settings)}`);
    return this.settings;
  }

  update(info: Info, color?: string): void {
    
  }

  updateTheme(color: string): void {
    this.settings.AppTheme = color;

    this.storage.set('userSettings', JSON.stringify(this.settings));
  }

}

export interface Info {
  Name: string;
  Sex: string;
  DOB: any;
  TOB: any;
  POB: string,
  Email: string;
  City: string;
}

export interface Settings {
  Notifications: boolean;
  AppTheme: string;
}

I take settings from this provider when the app is loaded and things work very well when I do ionic serve.
Now I build the app and run it on my android device, the theme is not updating on the device (in simple words IonicStorage is not being used).

What can be possible reasons? Is IonicStorage only available on browser?
Please help, with regards and thanks.

There is no need to manually stringify and parse things. Just store and retrieve ordinary objects, and Storage will take care of the details.

I suspect you might be attempting to interact with Storage before it is ready. Always wrap your interactions with it in a ready().then() block either directly or indirectly.

I changed the InitSettings function to this wrapping it under platform.ready:

  initSettings() {
    this.platform.ready().then(() => {
      this.storage.get('userSettings').then((val) => {
        // console.log(`UserInfo ${val}`);
        if (val == null) {
          console.log('Found val for userSettings.color null');
          this.storage.set('userSettings', JSON.stringify(this.settings));
        }
        else {
          this.settings = JSON.parse(val);
        }
      });
    });
  }

but it still doesn’t work on android, I am restarting app using window.location.reload after theme change to apply changes to all pages.
What else can I try, please help.
Thank you very much.

When I tried to debug the app on chrome it shows me this error:

Error: Uncaught (in promise): QuotaExceededError

When I googled this it shows that it occurs either when localStorage is fully filled or when the browser doesn’t allow access to storage at all, how do I make my mobile device to access storage?

I’m having the same issue, this is the complete stack trace:

core.es5.js:1084 ERROR Error: Uncaught (in promise): QuotaExceededError:
at c (polyfills.js:3)
at c (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.es5.js:4140)
at t.invokeTask (polyfills.js:3)
at r.runTask (polyfills.js:3)
at o (polyfills.js:3)
at IDBTransaction.invoke (polyfills.js:3)

I’m using the settigs servis as recommended in Ionic super template.

I tried to find out the solution and couldn’t find one, so I switched to native storage and feels it works really fine for me + its fast too :smiley:

By chance, tonight I discovered that the hard disk of my windows PC was almost full, which was generating problems of virtual memory, and specifically in chrome problems with the local storage

But mine was not, any solution for me? :frowning:

I had the same issue with chrome and not firefox so I restarted my computer and it fixed the issue with chrome.