Data persistence/iCloud

Hi guys,

I’m new here and have been playing with Ionic and Cordova. Very interesting so far!

Anyway, I was wondering if anyone could answer the following for me please? Regarding iOS.

If an app has data inputted by the user (e.g. todos). How is persistence handled? Another important point is - what happens when a user upgrades their app, does the data get saved indefinitely/safely?

Has anyone provided iCloud features or am I jumping the gun a bit?



You can use phonegap (to access local data storage on the phone) or you can go to a backend as a service (several exist)

So you then end up with the following layers

Angular JS
Database / backend as a service

You have to choose one that matches your needs but look at Parse, Kinvey, Firebase & various Mongo DB hosted solutions

Thanks Alexb, really appreciated. Looks like Cordova can access local storage too!



If you use a backend like Kinvey, their javascript client manages the local storage for you on the device as well as the backend.

If you are rolling your own, Angular-cache is a nice interface for local storage.

Hmm, this is posing all kinds of new questions - namely - is the device online?

What’s the best approach to test if the device is online and saving data externally if it is? I’d like to minimise the opportunities for data loss!



Now you’re getting into a pretty complex area. The best user experience will come from a local database such as the Web SQL Database (sqllite) through Cordova, but that would limit your data to one mobile device.

You would then want to synchronize your local data with data on a server when your mobile device is online. Example backends were recently discussed in this topic: What backend solution would you recommend?.

Now, With multiple users, or even just multiple devices, your distributed databases will need to reconcile conflicts. For example if you update the same record on your iPhone and your iPad while offline, how should the conflict be handled? How will you handle ID creation within different databases and maybe even with different schemes?

And then, of course, you have to consider how to present this all to the user with asynchronous communication. I have looked but never found a framework that offers all of this. Perhaps the client manager that @Calendee mentioned? Let us know if you find one.

To test if the device is online :

if( angular.isDefined(navigator.connection) && angular.isDefined(navigator.connection.type) && navigator.connection.type === 'none') {
return false;


if(navigator && navigator.connection && navigator.connection.type === 'none') {
    return false;

You must have the Cordova Network Information plugin installed :

cordova plugin add


Thanks @Calendee, I was wondering - is there a list of all the plugins that Cordova has that Ionic supports? That would be useful!

I’m going to have a play tonight and see what I can get working. I imagine a quick check to see if the device is online or not and save to either local storage or cloud. The tricky bit, as you mention @jeff_collier, is the issue of ensuring data isn’t put out of sync…


I was reading up on Cordova and found this plugin that might help with this issue:

It says the db is backed up by iCloud and should mitigate the localStorage/webSQL iOS data loss issue.

I’ve been using $window.localStorage[key] in my ionic app on iOS. I’ve been facing an issue where the OS will clear localstorage based on how much memory is available on the device (as described here: I’m only storing small strings and thought this was bizarre. Has any faced similar issues?

I had this happen when I recently updated iOS. After the update, my local storage had been deleted.