Device-Bugs
Device-Bugs copied to clipboard
(iOS)(Cordova) localStorage can get unexpectedly cleared when device storage is low
Platforms:
Cordova apps on iOS, Safari on iOS
Summary:
localStorage might get cleared without user consent
How to reproduce:
- Write lots of data to
localStoragein your iOS Cordova app - Quit the app
- Make the device storage low by downloading music etc.
- Observe localStorage inside cordova app being cleared
Background
iOS5 introduced a feature where certain application data contents (non-permanent cached data) might get cleared if the device is running out of storage.
http://www.marco.org/2011/10/13/ios5-caches-cleaning
It seems the behavior also affects Cordova applications using localStorage. There are some reports in the internet about it and some of our internal testers reported the same issues on their iphones (on app built with Cordova 3.6).
http://forum.ionicframework.com/t/ios-localstorage-persistence/20004 http://forum.ionicframework.com/t/localstorage-is-it-cleared-after-app-restarts-periodically-in-ios/21819
Apparently the then-PhoneGap bug related to this was fixed long time ago, but it seems it reoccurs with new versions of iOS.
Related Android issues
There were also reports of bugs in Android 5 (Chrome 42) about last localStorage write being lost if the app is killed, but apparently the bug was quickly fixed https://code.google.com/p/chromium/issues/detail?id=479767
Any word on a fix for this?
@pmramos two options PouchDB or LokiJS which have tutorials linked off from http://gonehybrid.com/dont-assume-localstorage-will-always-work-in-your-hybrid-app/
The preferred method looks like LokiJS with an unofficial filesystem adapter to persist the in-memory data.
So switching to Sqlite or pouch or lokijs is the only option? Should i assume this will be not be fixed from apple/cordova?
I am using pouchDB and get this issue only when the app is first install and the user "hard" close the app..
Anyone has solution to this issue?
apple sucks... still no fix
Any word on how it works with the new webview?
@amritk We switched to WkWebView and experience still this problem.
Does this apply also for IndexedDB??
@amritk We switched to WkWebView and experience still this problem. I'm using
"cordova-plugin-ionic-webview": "4.1.3",and the problem with suddenly cleared cache still exists. iOS phone have 120GB of free space. iOS 13.5.X
what could be the problem?
For everyone with this issue, use something like this: https://github.com/TheCocoaProject/cordova-plugin-nativestorage
Yea we ended up switching to
https://github.com/crypho/cordova-plugin-secure-storage