iOS localstorage persistence

#2

There’s nothing special to do - it should just work without hassle. Do make sure that you are using localStorage.setItem() / localStorage.getItem() and not the localStorage[“xxx”] style syntax. I’ve noticed on some browsers the [ ] syntax can behave like you described.

#3

I’m utilizing the localstorage factory that max did. I’m setting the object using $localstorage.setObject(‘user’,{id:id,expires:time}) and retrieving it within a resolve on my controller with $localstorage.getObject(‘user’). It redirects the user to the Sign in page if the id value is empty. Though it only persists for a short while before I reopen the app and I’m directed to the signin page

#4

I’m not familiar with the localstorage factory method but maybe try the ‘old-fashioned’ way and see if it works differently.

#5

check out https://github.com/jmdobry/angular-cache . You can configure cache to be sessionStorage or localStorage. localStorage will not be wiped out unless the app is uninstalled or upgraded.

#6

Have a look at LocalForage https://github.com/ocombe/angular-localForage

1 Like
#7

Do you thing its better to use LocalStorage than SQLite ?

#8

I have not only tried the $localStorage factory but I have tried angular-cache as well as localForage and to no avail. They work for a few minutes though once I close the app and go into another app for more than a few minutes then try to reopen the app, the local data has been cleared entirely and I am back to my landing page. I have tried the standard and pure local storage method as well and yet nothing seems to work.

#9

We use it and have app settings persist for weeks without any issues with this library

#10

We use this : http://ngcordova.com/docs/plugins/sqlite/

Works without problems on ios & android.

#11

Still want to stick to localStorage for the sake of simplicity however the data is still randomly cleared out. i could close the app and go into most notably Flipboard for a few minutes, reopen my app and the localStorage has been cleared entirely on ios. i have tried every single possible solution regarding LocalStorage and to no avail which is beyond frustrating at this point. What could possibly be the issue so I could get simple login data to finally persist!

#12

can you post your angular-cache configuration or code? I am using angular-cache to persist to localStorage which never gets cleared unless I uninstall the app

#13

What I have noticed is that the localstorage persists if there is memory on my iOS device. However, if it’s at zero mb, the device will purge the localstorage from my app. How do I avoid the storage being removed if the device is low on storage?

#14

I dont think you can @radbeta . That is why it’s not recommended to have your app depend on localStorage, but use something a little more robust like SQLLite, although I’m not 100% sure you wouldn’t run into the same issue with low device storage. Might be something to research

#15

I’m facing the same issue, but it happens after more than 4 hours. While my mobile has enough space free…
Did anyone of you find any solution for it?

#16

Its most certainly just like @radbeta described, low internal memory on iPhone. It that case iOS automatically delete some caches and localstorage.

#17

Use sqlite.

There is no way to guarantee that local storage will persist.

In App Purchases (IOS)
#18

LocalStorage works well if there is sufficient memory on the device(usually more than 20mb at least) though depending upon what Backend database or service you may be using, you could always check if the user still has permission to access your service if their login token has not expired. Firebase does an excellent job of providing a few line snippet making it seamless to check and edit the expiration length of the token in the dashboard as well as providing user login through various services such as Facebook, Twitter etc. If LocalStorage is what you need, be sure you don’t store your data in a Directory that won’t persist or that iOS or Android purges. Storing your data in the Documents Directory gives you the best outcome and avoidance of the data being wiped arbitrarily though it’s not a guarantee.

#19

@radbeta We are having the exact same issue! What exactly did you do to persist local storage data? We use Firebase as our backend and Firebase automatically stores the auth data (w/ expiration token & other info) in local storage. But when users don’t have sufficient memory on their phone, local storage is wiped out and the users are logged out.

How exactly do you suggest persisting firebase auth data that was stored in local storage? Thank you so much for taking the time to solve this issue; we really appreciate your help!

#20

If you haven’t yet figured it out, reference the links below. They all achieve what you are looking for with auth and session persistence while be exempt from data purges when the device is low on disk space.


(encrypts data and auth data is sensitive so this may be best)

#21

Maybe your iOS device automatically delete some caches and local storage because you don’t have enough internal memory on your device.