LocalStorage in app being cleared on reboot in iOS8

It seems that upon force-rebooting my phone (holding down the power and home buttons until the device reboots), localStorage for my app is cleared.

I’m seeing the same behavior when I open my app after a few hours without use, but I haven’t been able to pinpoint that issue exactly yet.

Has localStorage changed in iOS 8?

1 Like

I got the same issue. Any ideas?

I’m also facing problems where local storage seems to be cleared sometimes. But I cannot reproduce it by home + power reset.

One thing I suspect is that it appears when switching between Xcode debugging and “normal” use of the app … But I’m quite sure it has also appeared when restarting the app after it was regularly installed via iTunes …

Same problem here… we have an app in production and someone say that after about one month all data are cancelled. I don’t have idea how to reproduce this and on our phones android and ios never happened this. Someone found some solutions? I’m planning to switch to sqlite… what do you think about this?

Today I had the issue again on two devices with ad hoc installations (via iTunes). Tried for hours to reproduce it but without success. Then I did some research and found several discussions about this bug (e.g. http://stackoverflow.com/questions/27053590/localstorage-in-app-being-cleared-on-reboot-in-ios8).

Unfortunately no fix, only the workaround of using file API. I also searched the Cordova JIRA but the only related issues I found were old and closed.

Goal of my current project is to reuse the source of the hybrid app as much as possible for a web app. So sqlite is perhaps not the best way to go. Its also quite complex compared to simple local storage operations.

I’ve been using simple LocalStorage in my app. App has been updated via iTunes multiple times. I can hard reset my phone over and over and never cause local storage to be lost. So, for me and my users, LocalStorage is pretty stable.

People, i have an iphone and it is happening to our app that in production… The ios is cleaning the data… I think that is related with the fact that my iphone hasnot free space.

Just tried reboot, and also hard reset on my ios device, no problem. I’ve been using LocalStorage, and seems pretty stable to me.

Localstorage is definitely unstable on iOS. Apple consider it “temporary” storage and can/will clear it without your knowledge.

PhoneGap attempts workarounds for this, but all around you shouldn’t be using it for data you require to be persistent.

Your other browser storage engines:

WebSQL a deprecated web standard. This is supported on iOS and Android, however the latest version of iOS’s WKWebView does not include it so the future isn’t bright.

IndexedDB is the recommended persistent storage engine. However the support in iOS 8 is broken.

Cordova SQLite Plugin exposes an API which is compatible with the WebSQL API - just change calls from window.openDatabase to sqlitePlugin.openDatabase. Boom, persistent storage in a native-backed engine.

Problem with the plugin is you now require Cordova - you can’t test in the browser. So either write your own wrapper function which calls either window or sqlitePlugin depending on the environment, or use an existing wrapper like localForage (forage, not storage).

2 Likes