Best method to store global application preferences?

Been investigating the best way to store global app preferences that the user can set up on their device for my apps.

I note that ng-Cordova has the $cordovaPreferences plugin which seems to make this task easy.

However, in looking at the documentation behind that, there seems to be a LOT of contradictory information on HOW to set up the preferences file for Ionic/Cordova. I am talking about global preferences that the end user can configure, not the fixed build preferences.

Some sites (including the plugin docs) say to use Cordova.plist in the root folder. Others say that the preferences have now been moved into the config.xml file. Still other sites say I should create a config.ios.xml in the /platforms/ios folder??

It seems to be a moving target. I would appreciate it if anybody can point me to current documentation on how to set up user changeable preferences for my Ionic apps.

1 Like

For settings that the user of the application can define, just use the localStorage to store his preferences.

You can easily create a SettingsFactory that stores and retrieves settings.


There is a problem with localstorage, when app is auto updated at user’s end, all localstorage entries get cleared.


Thanks for the tips guys. At present I use a local SQLite database to store the user preferences as well as other app data.

I was wondering if there was an easier or recommended way to do things.

I’d like to preserve the settings across application updates. Not so much if the user deletes the app and reinstalls later.

I wonder if there is a Cordova plugin that allows the app settings to appear in the device’s “Settings” app? Much as a lot of iOS apps have settings that are available via the iOS Settings app, alongside the native app settings like Safari, Mail etc.?

What devices do you see that happening on @mrameezraja? I’ve been testing with some android and ios devices and haven’t noticed that, but I’d hate to have some users lose their preferences on update!

I have tested this problem on iPhone 4,5,6. This happens when app is updated on app store and then on user’s device.

Can anyone else confirm whether or not local storage is lost when doing an app update please?

I was under the impression that localstorage was now persistent across updates but would be removed if you delete the app.

I may well have to reconsider my approach as I was going to save data in local storgae but if its lost after an updaet then it’s not suitable.

1 Like

I’m curious as well. I have only tested ios with local xcode builds and android with direct apk installs, so I haven’t seen for myself whether local storage is lost on app store updates.

Can anyone else confirm whether or not local storage is lost when doing an app update please?

On android, the rule is as follows:

-The Local storage is not erased if we do an update.
-However if we first deletes the old version and then installing the new one, the data is lost.

Thanks for the confirmation @jimibi.

Can anyone confirm the situation on iOS please?

Hi @mhartington - sorry to message you direct, but the response so far seems unlear - just wondering if you know whether local storage is lost when doing an iOS app update?

Apparently for Android it is not, but there is at least one user who says that in iOS it is lost…

I’m looking at storing all my user generated app data (e.g. notes, favourites, preferences) in local storgae, and I don;t want them to be lost if I release an update.

Many thanks

So pretty convenient that sworkit had an updates this morning :smile:

So local storage is not lost when updating an iOS app.
The only time local storage is erased is when the app is deleted.


@mhartington is absolutely right. :smile:

localStorage, Web SQL, IndexDB are all persistent across updates for iOS and Android. They are however wiped when you delete the app completely.

Another thing just to note, is that if you plan to use Crosswalk later, it currently will not transfer these variables to the new Chromium webview. I’ve been trying to reach out to some devs with a greater skill set in those regards to create a plugin for this purpose but nothing quite yet.

If you aren’t using Crosswalk in the future, or if you don’t have any users on a version of your app pre-Crosswalk, these are very safe. Sworkit has been using them for 2+ years and 20+ updates.

1 Like

Correct, local storage will be wiped when you upgrade to crosswalk.
We’re running some ideas as to what would be the best solution for this, whether that would be a storing data on the actual device file system or something else.

1 Like

Thanks @mhartington - that’s just what I was hoping!
Also, @gylippus thank you for the info regarding Crosswalk. Good to know. I haven’t started using it yet so should be ok.

@mhartington I think that the best way is using something similar than this no? but his project doesn’t works correctly.

Anyone has tried

For what it’s worth… On IOS: I have made the observation that local storage can bite you in the behind if you need to read settings while the app is launching. There is a delay, the api not immediately ready. Also noticed on occasion that local storage has been updated with new value for a key which is not retained when force closing the app. Also, local storage is bound to the current domain which will not work if you need access to the storage while browsing external domains (embedded device for example that serves parts of an app). However, app preferences are not restricted to one domain and are immediately accessible on device ready event. Something I had trouble with using local storage.

Beware that localStorage can randomly be cleared on IOS devices when/if the device runs out of space…

Unfortunately I have run into this myself in a Ionic cross platform app.

So I use files instead now and not using localStorage any more :frowning:

Hi Sir , I developed my app using ionic framework. In this I need’s to skip login page when user already logged in to the app. if user didn’t login default show login screen. I maintained session entire app. Recently I found Sharedpreference plugin. I stored session data into the sharedpreferences. but How can I restrict pages when i open the app. I am confused please help me. How can I write code in app.js file.