Is there a LocalStorage limit on iOS when app is built?

I am using LocalStorage to store cached data. All of a sudden I am getting the following error in both simulator and when I build the app on my iPhone:

Error: QuotaExceededError: DOM Exception 22

Doing some searching, this error seems to be related to a 5MB LocalStorage limit to private browsing on Safari iOS. No one mentions it being linked to an iOS app.

Even though it’s a compiled iOS app, is it still restricted by such a limit?

Is there a way to increase this limit or do I need to look at another option for storing data.

1 Like

you should use another option to store your data --> sqlite, pouchdb, lokijs and so on :wink:
localstorage is not that persistent. it can be erased in some cases… like upgrade from iOS8 to 9 --> all of our apps lost their localstorage data. So we decided to not use localstorage anymore.

1 Like

Thanks! Our of interest, what was your preferred solution for storing data?

Obviously cached data doesn’t need to be consistent for me. There is however other data that I would like to keep between upgrades so I definitely need to look at other options.

In regards to the QuotaExeeededError I am getting do you know what the limit is by any chance?

the limit is 5MB in general i think. For the chrome browser you can increase that limit programmatically till 30 or 50mb … something like that. but thats not recommended.

It depends a little bit what do you want to achieve. if you need synchronisation with your backend db (for offline usage) i would use pouchdb. If you only want to store data (many data sets) you can use sqlite.

If you are storing only some flags and so on lokijs is a good memdb with the possibility to store all the data to a json file --> and the good point per default it uses localstorage --> so if you ever want to run your code in browser for testing or production purpose -> it is working :wink:

Thanks for that! I primarily want to store cached data and a few items of authentication/app specific data. Everything is temporary and basically caches data from the server.

I tried PouchDB but found it was loading data out of order. Might be from me using $q.when() but not sure.

So now I’m giving lokijs which seems more promising and based on your description might be the best option for me anyway.

Do you use lokijs? If so, what adapter are you using? I’ve opted for loki-cordova-fs-adapter for now and just using LocalStorage in the browser.

Really appreciate all your help with this!


Sorry, one more question. That adapter I am using requires the cordova-plugin-file. Reading the docs on NgCordova it says:

* Files persist across app restarts and upgrades, but this directory can be cleared whenever the OS desires. Your app should be able to recreate any content that might be deleted.

** Files may persist across app restarts, but do not rely on this behavior. Files are not guaranteed to persist across updates. Your app should remove files from this directory when it is applicable, as the OS does not guarantee when (or even if) these files are removed.

*** The OS may clear the contents of this directory whenever it feels it is necessary, but do not rely on this. You should clear this directory as appropriate for your application.

Have you had any issues with this? Worst case scenario for my app is they’d have to log in again. A little annoying. Have you experienced any data being deleted?

nope i lost my files only on pupose… like on android you have an installed app list in your device settings --> there you can clean the appdata and this will remove also this files.

there is a corodva file adapter for lokijs --> to use filesystem:

it uses internally the dataDirectory of your filesystem of your app --> a little look in the documentation:

so if it works correctly --> your have there read and write access, it is persistent and os does not clear it on its own aaaand on ios it is not autostored in the icloud :wink:

1 Like

I’m only familiar with SQLite but, after reading a bit about Loki and Pouch, arent all three still persisting to local storage when used as in-browser databases? If not necessarily, where are these ultimately writing to?

Pouch is a couchdb system and sqlite a sqlite db system for the client-side. Nothing special, but if you are using Pouchdb there are more predefined functionalities for syncronisation if the device goes offline and online (if your app need this).

You can achieve this with sqlite as well, but with a lot of more work.

lokijs is something like a fast mem-db alternative. it simply holds all stuff in memory and to store the stuff persistent you can write it to localstorage or a file.
Since i noticed that localstorage gets cleared in many circumstances i use lokijs to store stuff like authentication data and so on… everything i previously stored in localstorage.

If i only need many data offline --> you use sqlite or pouchdb.
In some cases lokijs is more flexible because you do not have to run sql-statements if you want to extend an existing collection (it is more like documentbased systems like mongodb) or add a new one.