Localstorage - is it cleared after app restarts/ periodically in iOS?

My app in emulator 5.0 work, in real device not.

Have you considered localforage ?

1 Like

This seems like a pretty big bug, I have an app for android with crosswalk that heavily relies on localStorage data.

Hope this doesn’t enter into crosswalk(using version 11.xx), will have to check every time I update it. For the moment localStorage stores just fine for several months already (updates included)

For Android there is a comment at https://code.google.com/p/chromium/issues/detail?id=479767 that suggests that it is “just” the last entry made to localStorage that can potentially get lost.

Has anyone tried a workaround whereby a dummy / sacrificial last entry is made leaving the other entries intact?

I wish Objective C was not that cryptic to read :confused:

1 Like

I have an app in the App Store for more than a year now that uses LocalStorage and never had any problems with that. Data was never lost, so I wouldn’t worry about that.

Update: I now actually have experienced problems due to low memory and iOS clearing the localStorage because of that…

You have other options as well, like IndexedDB (only use that on Android), WebSQL, SQLite, or use PouchDB, which will encapsulate all of them. It so happens that I just wrote a blog post about using Ionic with PouchDB :wink:

Objective-C is exactly why Swift became popular :smiley:

BTW Ive not seen any problems with using local storage on iOS and Android. But it is really only designed to store simple stuff (credentials, preferences, etc). For more complex data, you’re better off with a real database. We are using Couchbase Lite locally and have a built an API on the server side that stores to a cluster of Couchbase servers. Syncing is handled by Couchbase’s builtin replication (two-way sync for ‘free’ essentially) to Coucbase Sync Gateway.

So I figured out what that “event” was.

My understanding (and that matches the experiments with my test app) is:

a) LocalStorage works well (tested on iOS 8.3 / iphone 5) - not randomly cleared.
b) However, there is one corner case in which I have seen that to be cleared repeatedly - and that is when the phone runs out of space. So my phone was very low on disk space - and periodically the icons on the phone face would go “Cleaning…” (where the app name is written) - and when that status showed up against my app - that meant that the localstorage has been wiped off.

I just made a 2 gigs of space on the device - and have had no problems of localstorage ever since.

Hope this helps.

Were hitting this issue with our app. LocalStorage will wipe when the disk space on the device gets low. Did you find a solution to this?

There seems to be a bug with chromeview affecting those that use crosswalk in their apps that causes the localstorage to be reset each time the app restarts. (https://code.google.com/p/chromium/issues/detail?id=481380)

The problem is now resolved and I can confirm that it is fixed when using the latest version of crosswalk (14.42.334.0)

SO that is expected behavior.

I am not sure what android has available but for iOS there is NSUserDefaults that persist until the user wipes the app off the phone. I’m sure there is a plugin for that, and one equivalent for android, i just haven’t looked.

I’m also working on an ionic app and during testing phase on my phone I had no worries about local storage which was persistent.

Once deployed on Apple App Store some users complained about losing data time to time.

So my conclusion is that the local storage is not reliable at 100% because of iOS cleaning some apps or some strange behavior of safari in private mode.

Conclusion : dot not use local storage for sensitive data that you want to persist.

Personally I ended up using localforage and indexdb driver.

1 Like

With Android > 5 I noticed that localStorage is cleared when one closes the app via task manager.

Maybe I give SQLite a try.

This is the first time i hear about this, are you sure, do you have some more info about this?

I’m using IonicView to test my app on my iPhone, before may update on the app the LocalStorage was working fine, I could close IonicView and the localstorage would be kept.

However, after May’s update not only the IonicViewApp keeps losing my login but also it doesn’t keep anything about the localstorage if I close the app, so I ended up losing interest on it because of that =, I wish I’d never updated it, I was so happy with my “offline” House Budget test app.

Maybe this can be related to the problem you’re facing. Are you using the IonicView to test?

i havnt tried this yet, but they claim that local storage cannot be trusted:

Two iOS users told me that my app had deleted the values that I’ve stored using localstorage.

Hi I’m using localStorage in my hybrid app developed using Ionic framework. Everything works fine, but recently we’ve noticed that if I keep my app in background for a longer period,like 5-6 hours, and while I re-open the app, it looses its values in the localStorage. But if I force quit my app and re-open it, it works fine, and then it gets all the values in the localStorage… Quite strange for me, as this only happens in IOS, and Android works absolutely fine…

Recently, iOS users have been telling me that they continually need to re-login to the app. Auth tokens are stored in localstorage for 1 month. Localstorage is being wiped regularly for these users. I have been unable to pin down why, and it isn’t for every user. I’m going to switch to storing things on disk.

Hi. I just signed up as I am interested in following what the ionic ecosystem does around enabling offline support, and I found this thread.
We’re actually finalizing porting our SQLite sync framework as a Cordova plugin for Android (Android only for now, iOS later). A world-class powerful sync framework: bidirectional differential sync, full-CRUD, ultra-fast bulk sync… while being very light and easy to integrate.
We were wondering: can there be a future for it among ionic developers? Would this interest you? (and yes, we’re considering open-sourcing it, but we haven’t decided yet because we need to find an economic sense for us to this… If you want to comment, please do!).