Data persistence/iCloud


#1

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?

Cheers!

Rikki


#2

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

Ionic
Angular JS
Phonegap
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


#3

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

Best,

Rikki


#4

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. https://github.com/jmdobry/angular-cache


#5

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!

Cheers,

Rikki


#6

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.


#7

To test if the device is online :

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

or

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

You must have the Cordova Network Information plugin installed :

cordova plugin add org.apache.cordova.network-information


#8

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…

Rikki


#9

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.


#10

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: https://www.scirra.com/forum/wkwebview-webstorage-can-be-cleaned-by-ios8_t120439). I’m only storing small strings and thought this was bizarre. Has any faced similar issues?


#11

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