It works fine on browser but doesnât work on my android device, I even tried adding this thing in storage.ready() but still doesnât work, any way I can handle the issue?
Thanks and Regards.
EDIT 1:
Sorry I misclicked with incomplete quesiton.
You will have to provide more information for us to be able to understand what you are doing:
In which provider does this live?[quote=âakshatbhargava123, post:1, topic:96472â]
if (val == null) {
console.log(âFirst Time storage setup startedâŚâ);
this.storage.set(âuserSettingsâ, JSON.stringify(this.settings));
}
else {
console.log(Fetching settings from localStorage...);
this.settings = JSON.parse(val);
}
[/quote]
Can you explain the logic behind this in plain English please?[quote=âakshatbhargava123, post:1, topic:96472â]
setTimeout(() => {
this.appTheme = this.User.getSettings().AppTheme;
console.log(App.component ${this.appTheme});
}, 300);
[/quote]
Where exactly is this code?
What is this.User.getSettings()?
is because I wanted the plugin to give some time to initialize so I gave a hardcoded delay.
What I want to know?
An approach so that I can initialize localStorage or get data from it before my app code is being executed, in simple words before it jumps to next page from app.component.ts.
That provider has to return a promise that your normal code then can use - everything will always fail. Theoretically it could just return this.storage.get('userSettings'). Best get rid of this.settings in the provider as well, the storage is authority.
If you donât want to âwaitâ for the storage every time, you have to implement your own promise that returns a local cache (what your this.settings tries to be right now) if it exists, otherwise waits for storage again and fills the cache before then resolving that promise with the value.
Donât use setTimeout() here. Think in terms of contracts. The way you have written your provider, nobody outside it has any way of knowing when it is safe to call getSettings(). I would write it like this:
Ok though I feel this one easier
Are there any drawbacks of native storage instead of ionic storage? I think it is easier to implement.
Thank you again.
Yes. It wonât work in a browser environment, so developing using ionic serve will become impossible. Ionic-storage works seamlessly on both browser and device.