I have to create an application that has functionality similar to the contacts app. You can add a contact on the client's iPhone and it should get uploaded onto the client's iPad. If the client updates the contact on their iPad, it should get updated on their iPhone.
Most of this is fairly straight forward. I am using Parse.com as my back end and saving contacts locally with Core Data. The only problem I'm encountering is managing contacts when the user is offline.
Let's say I have an iPhone and an iPad. Both of them have the same up-to-date version of the online database. My iPhone is offline.
At 10AM I update the phone number for a contact on my iPad online. At 11AM I update the email address for the same contact on my iPhone but I'm offline.
Later that day my iPhone gets online and checks the servers for changes. It sees that all of its changes are more recent (checking an updatedAt timestamp property) and doesn't download the new phone number for the contact. Instead, it updates the properties that have changed since the older 10AM update and overrides the new phone number along with the email address.
How am I supposed to manage the online/offline problems encountered such as the one above?
I was thinking to have an updatedLocally and updatedOnline property on every object. This way if the two don't match I can do a diff-check and use the most recent one for conflicts but this doesn't seem like the cleanest solution. Has anyone else encountered this problem? If so, how did you solve it?
Aucun commentaire:
Enregistrer un commentaire