Ionic local storage lost after store version update

Hi,
I’ve made a new version of my app (for ios & android).
The app uses local Storage, but when the users download the new version, all the local storage is reset to their default value.
For set and get the local storage, I use this functions:
set: function(key, value) { $window.localStorage[key] = value; }, get: function(key, defaultValue) { return $window.localStorage[key] || defaultValue; }, setObject: function(key, value) { $window.localStorage[key] = JSON.stringify(value); }, getObject: function(key) { return JSON.parse($window.localStorage[key] || '{}'); }, clearKey: function (key) { delete $window.localStorage[key]; }

Anyone can help me please?
Thanks!

1 Like

Well the LocalStorage is not database you want to use you production App. It is not database at all!! There are several ways you can lost your data. Even the everyday memory cleanup will do. Once you want to address the phone memory first I would advice to use (at least) the localForage respectively an angular-ish wrapper around localForage.

  • localForage is capable to handle whole objects or arrays (not just strings like LocalStorage)
  • your data will be very likely stored in IndexedDB or WebSQL (thus save from cleanup) without need to use their native (not so friendly) API. [I believe you should install Cordova IndexedDB plugin anyway]
  • localForage API looks almost like MongoDB or CouchDB, so one day you will be able to use a real database wit no extra hassle.

You can also try lovefield

1 Like

I need a synchronous plugin :frowning:

EDIT: using localForage i’ve solved. Thanks