重建应用程序后,Ionic Native Storage 不会持续存在

Ionic Native Storage is not persisting after rebuilding app

我正在使用 ionic 3 本机存储并存储如下值:

this.storage.set('myValue', this.value);

然后我重建应用程序并尝试获取该值,它 returns null:

this.storage.get('myValue').then(value => {
console.log('My value: ' + value);
}) 

结果是:我的值:null

不确定为什么它这样做不是存储假设将其存储在数据库中所以我是否重建应用程序应该无关紧要?

您需要安装SQLite plugin

When running in a native app context, Storage will prioritize using SQLite, as it's one of the most stable and widely used file-based databases, and avoids some of the pitfalls of things like localstorage and IndexedDB, such as the OS deciding to clear out such data in low disk-space situations.

ionic cordova plugin add cordova-sqlite-storage

试试这个;

this.storage.get('myValue').then((data) => {
console.log('My Value : ' + data);
})