Reputation: 21
I have been stock for an hours because of this issue on @ionic/storage-angular it seems that its not working on android?
In my case it work fine on browser the data was stored in the IndexedDB. but when I going to run the app in the physical device(USB debugging) the storage is not working.
After googling I still can't find a related thread the same on the issue that I am currently facing.
Maybe anyone have an idea? Please share your thoughts. Thank you in advance.
Here's the code..
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage-angular';
@Injectable({
providedIn: 'root'
})
export class StorageService {
constructor(private storage: Storage) {
this.init();
}
async init() {
await this.storage.create();
}
async set(key: string, value: any) {
const encryptedData = btoa(escape(JSON.stringify(value)));
return await this.storage.set(key, encryptedData)
}
async get(key: string) {
return new Promise(resolve => {
this.storage.get(key).then((value) => {
if(value == null) {
resolve(false);
} else {
resolve(JSON.parse(unescape(atob(value))))
}
})
})
}
async removeItem(key: string) {
await this.storage.remove(key);
}
async clear() {
await this.storage.clear();
}
}
Upvotes: 1
Views: 660