How do I safely synchronize data on a remote database from an iPhone app?
I have an old Java EE web app that uses a database to store data input by users from the app. I'm now in the process of designing an iPhone app that will allow users to enter the same information on the iPhone and have that data submitted to the existing database via a Restful web service.
On the iPhone I want to allow users to be able to input data even if they're not connected to the network and have it automatically synced to the server once a network connection is available. To achieve this I plan on using CoreData to store records locally on the phone.
The Use Case I'm struggling with is this; if a user enters data in offline mode then goes online (web app) and enters data before the phone uploads the offline data, how do I prevent the phone from blindly overwriting the data entered on the web. I would like to be able to show an error to the user stating that online edits have occured that they need to pull before they can push their offline changes.
I'm sure this is a Use Case that's probably common. Does anyone know of any design pattern(s) that deals with this problem?
Thanks.
You can have your web service provide a 'version' that is tracked by the iOS app. For example an md5sum of the rowcount or the last row in your online database. Its basically a versioning system so your mobile app can check and see if its version of the data matches the web services. Your mobile app connects to the internet, checks the version of data in the webapp and compares it to its last known version. Merging then becomes a problem of course but that seems outside the scope of your question.
It seems, you have multiple users/devices with read/write access and a distributed database, where particular devices have restricted memory and CPU power, run on different OSs and are also offline for an indeterminable amount of time.
This's probably the worst scenario you can get ;)
Unless you can reduce the complexity through rigorously restricting use cases, the requirement to synchronize the databases and keeping the data logically correct is an extraordinary complex challenge.
For related further info, you may take a look at CouchDB, TouchDB, RIAK, RIAK for mobile, simperium, apigee, cloudant (for mobile) - which may provide solutions.
Note, that not all solutions actually provide a (distributed) database on the device. TouchDB would, and RIAK at least talked about it.
链接地址: http://www.djcxy.com/p/62130.html上一篇: 什么是Web服务端点?