Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(iOS)(Cordova) localStorage can get unexpectedly cleared when device storage is low #64

Open
jakub-g opened this issue Oct 28, 2015 · 11 comments

Comments

@jakub-g
Copy link

jakub-g commented Oct 28, 2015

Platforms:

Cordova apps on iOS, Safari on iOS

Summary:

localStorage might get cleared without user consent

How to reproduce:

  1. Write lots of data to localStorage in your iOS Cordova app
  2. Quit the app
  3. Make the device storage low by downloading music etc.
  4. 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

@pmramos
Copy link

pmramos commented Sep 15, 2016

Any word on a fix for this?

@budda
Copy link

budda commented Dec 19, 2016

@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.

@praveenkumarsinha
Copy link

So switching to Sqlite or pouch or lokijs is the only option? Should i assume this will be not be fixed from apple/cordova?

@premtemp1
Copy link

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?

@i-me-mine
Copy link

apple sucks... still no fix

@amritk
Copy link

amritk commented Aug 16, 2018

Any word on how it works with the new webview?

@Bessonov
Copy link

@amritk We switched to WkWebView and experience still this problem.

@Marko-Matijevic
Copy link

Does this apply also for IndexedDB??

@qliqdev
Copy link

qliqdev commented Jul 7, 2020

@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?

@sandstrom
Copy link

For everyone with this issue, use something like this:
https://github.com/TheCocoaProject/cordova-plugin-nativestorage

@amritk
Copy link

amritk commented Jul 7, 2020

Yea we ended up switching to

https://github.com/crypho/cordova-plugin-secure-storage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests