2

I'm building an app with Cordova/PhoneGap.

It seems that upon force-rebooting my phone (holding down the power and home buttons until the device reboots), localStorage 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?

John Shammas
  • 2,687
  • 1
  • 17
  • 33

1 Answers1

1

I'm trying to find a solution too for this. It looks like localstorage is considered "unreliable" since iOS5.1. See: Phonegap iOS 5.1 and localStorage

unfortunately websql is going to be depricated, and indexdb is currently not supported in cordova (due to the fact that they use uiwebview and not wkwebview-- the new ios8 browser control that supports indexdb).

So I'm still scratching my head on this as well.

EDIT: I've been using "cordova-plugin-file" api to save/retrieve json as localstorage isn't completely reliable on ios cordova.

Community
  • 1
  • 1
Shai UI
  • 50,568
  • 73
  • 204
  • 309
  • Have you tried the File API? It seems to be able to store in various locations…but I can't find much information on how to use correctly. I'm concerned about saving things in the wrong place (which Apple won't like). – John Shammas Nov 22 '14 at 00:58
  • I'm reading about that right now, but I'm not a huge fan of the file api because alot of my data needs to be updated every few seconds. So not sure if I should write to disk all the time. There might be the sqlite plugin, but it seems so overcomplicated. :/ – Shai UI Nov 22 '14 at 01:00
  • I'm now reading that iOS 6 make localstorage reliable again? there's some kind of flag that persists it. 'WebKitStoreWebDataForBackup'. so maybe there's still hope for localstorage? not sure. still researching. – Shai UI Nov 22 '14 at 01:31
  • meh, i don't think that's gonna work. i'm leaning towards file api right now. let me know if you ever get localstorage to work. – Shai UI Nov 22 '14 at 01:59
  • I saw a lot about localStorage "supposedly" now being reliable again. But it just seems that when you have situations like low storage, the device will clear. – John Shammas Nov 22 '14 at 02:44
  • If it helps, here's my JS for the File API. Note this is for an AngularJS project, but it should be easy to adapt: http://pastebin.com/2zXs5HcB – John Shammas Nov 22 '14 at 02:45
  • thanks. maybe the way to go is doing a hybrid localstorage/file api. so if localstorage appears to be empty, just read from a file that you periodically save. – Shai UI Nov 22 '14 at 03:21
  • localStorage is reliable, the iOS 5 problems were solved long time ago. If it's deleted on iOS 8 open an issue on the cordova JIRA so cordova team can take a look – jcesarmobile Nov 22 '14 at 10:25
  • @John, Is there any update on this? One of our web app users might have experienced the same with iOS 8, but we don't have any details on the case. So I came over this SO question.. – Art Licis Dec 31 '14 at 17:33
  • @ArtursLicis no update. It seems that under certain conditions, the cache will be cleared on iOS 8. Looks like it only happens when low on storage, at least for me. Backups likely also clear the cache. I wound up using the File API and saving temporary items in the cache folder and permanent items in the Library folder. No problem upon submission to Apple. – John Shammas Dec 31 '14 at 20:25