iPhone应用程序和Web应用程序之间的双向同步 [英] Two-way sync between iPhone application and web application

查看:221
本文介绍了iPhone应用程序和Web应用程序之间的双向同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个依赖于MySQL数据库的Web应用程序,我正在考虑构建一个iPhone应用程序。此应用程序将允许用户在网络应用程序上浏览/插入/更新/删除他们帐户上的数据。

I have a web application that relies on a MySQL database, for which I am thinking of building an iPhone app. This app would allow users to browse/insert/update/delete data on their account on the web application.

最简单的方法是将iPhone应用程序构建为接口,即每个操作需要连接到Web。然而,我想iPhone应用程序有自己的离线版本的数据库。这不仅允许用户离线工作,而且还能提供更好的体验,因为在本地拥有一切意味着更快更灵敏的应用程序。

The easiest way would be to build the iPhone app simply as an interface for the web app, ie each operation requires to be connected to the web. However, I would like the iPhone app to have its own "offline" version of the database. This would not only allow the user to work offline, but would also provide a better experience, as having everything locally means a faster and more responsive app.

我会处理冲突通过使用时间戳和保持最新版本(我已经使用软删除,即当用户删除一个记录,我只是设置一个标志),但我还没有搞清楚如何处理插入。事实上,如果用户在离线(iPhone应用程序)和在线(Web应用程序)数据库中插入新项目,则会出现主键冲突(我所有的表都有一个INTEGER字段,自动增量作为主键)。我如何处理这个问题?

I would handle conflicts by using a timestamp and keeping the latest version (I already use soft-deletion, ie when the user deletes a record I simply set a flag), but I have not quite figured out how to handle insertions. Indeed, if the user inserts new items on both offline (iPhone app) and online (web app) databases, there will be a primary key conflict (all my tables have a INTEGER field with auto-increment as primary key). How can I handle this problem ?

我想到有一个两列主键,一个是自动递增的整数,第二个特定于设备。这样,通过Web应用程序添加的新记录将具有ID 1-web,2-web等,以及通过iPhone应用程序1-iphone,2-iphone等创建的记录...这将允许合并两个数据库没有冲突。你觉得这个想法是什么?

I was thinking of having a two-colums primary key, one being the auto-incremented integer, and the second being specific to the "device". This way, new records added via the web app would have ID 1-web, 2-web, etc. and the ones created via the iPhone app 1-iphone, 2-iphone, etc... This would allow to merge the two databases without having conflicts. What do you think of this idea ?

推荐答案

到目前为止最简单的解决方案是使用UUID。

The simplest solution by far is to use a UUID.

一个不那么优雅的解决方案是让iPhone id占用关键空间的一个定义的子集。例如,使用64位密钥,每个iPhone可以分配最高20位的特定模式。

A less elegant solution is to have iPhone ids occupy a defined subset of the key space. For instance, with a 64-bit key, each iPhone could be assigned a specific pattern of the highest 20 bits.

这篇关于iPhone应用程序和Web应用程序之间的双向同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆