Strange bug, ios local storage is being erased

I have tried to debug this, but don’t know much of apple settings and stuff.

In our app we store some data inside local storage. The user will come back to the app later (seems like its days) and the local storage values will be gone. Not getting a lot of info on what is done in between.

Have only heard of this happening on Iphones.
Any ideas on what to even test?


Wich native plugin are you using?

Should just be a browser thing. Or seems to be build into angular localStorage.setItem and localStorage.getItem

Here is the package.json

@angular/common”: “5.0.0”,
@angular/compiler”: “5.0.0”,
@angular/compiler-cli”: “5.0.0”,
@angular/core”: “5.0.0”,
@angular/forms”: “5.0.0”,
@angular/http”: “5.0.0”,
@angular/platform-browser”: “5.0.0”,
@angular/platform-browser-dynamic”: “5.0.0”,
@ionic-native/android-fingerprint-auth”: “^4.5.2”,
@ionic-native/core”: “4.3.2”,
@ionic-native/file”: “^4.6.0”,
@ionic-native/file-opener”: “^4.6.0”,
@ionic-native/firebase”: “^4.10.1”,
@ionic-native/geolocation”: “^4.5.3”,
@ionic-native/keychain”: “^4.5.2”,
@ionic-native/network”: “^4.5.2”,
@ionic-native/social-sharing”: “^4.11.0”,
@ionic-native/splash-screen”: “^4.3.2”,
@ionic-native/status-bar”: “4.3.2”,
@ionic-native/touch-id”: “^4.5.2”,
@ionic/storage”: “2.0.1”,
“branch-cordova-sdk”: “^2.7.1”,
“cordova-android”: “~6.3.0”,
“cordova-android-support-gradle-release”: “^1.4.4”,
“cordova-browser”: “~4.1.0”,
“cordova-ios”: “4.5.5”,
“cordova-plugin-android-fingerprint-auth”: “^1.4.4”,
“cordova-plugin-device”: “^1.1.7”,
“cordova-plugin-file”: “^6.0.1”,
“cordova-plugin-file-opener2”: “^2.0.19”,
“cordova-plugin-firebase”: “^2.0.2”,
“cordova-plugin-geolocation”: “^4.0.1”,
“cordova-plugin-ios-keychain”: “^3.0.1”,
“cordova-plugin-network-information”: “^2.0.1”,
“cordova-plugin-splashscreen”: “^5.0.2”,
“cordova-plugin-statusbar”: “^2.4.2”,
“cordova-plugin-touch-id”: “^3.3.1”,
“cordova-plugin-whitelist”: “^1.3.3”,
“cordova-plugin-x-socialsharing”: “^5.4.1”,
“es6-promise-plugin”: “^4.2.2”,
“ionic-angular”: “3.9.2”,
“ionic-plugin-keyboard”: “^2.2.1”,
“ionicons”: “3.0.0”,
“rxjs”: “5.5.0”,
“sw-toolbox”: “3.6.0”,
“zone.js”: “0.8.18”


This is the way of the world, and why you shouldn’t ever use localstorage directly. Instead use Ionic Storage. localstorage can and will be deleted from under you without warning.


Do we know why it gets deleted? This is just an ios problem?

Thanks for the link of Ionic Storage, I seem to remember seeing that. Wish we more of when ios clears it.

AFAIK, yes it only affects iOS, but as a programmer I don’t care why some external entity does something, just whether or not it might do it, and in the case of localStorage, it’s not guaranteed to persist. Ionic Storage is a clearly better choice for anything that needs to persist across app restarts, and people (ab)using localStorage to do in-app communication should replace that with a mutually injected service provider.

IMHO, you don’t really want to know that. Think in terms of promises and contracts, and your code will be much more robust. localStorage in a Cordova environment promises that what you put in it might be there when you try to read it later, and that is all you should rely on. Maybe the next version of iOS will change the conditions under which it gets cleared. Maybe the next version of Android will start doing something similar. You shouldn’t write code that will need to care.

OS will clear app data when the device storage is getting full.
This has happened to us too.

So, we switched to key-chain and then to Ionic Storage