iPad/iPhone 应用程序之间的云同步

发布于 2024-09-03 14:15:41 字数 339 浏览 2 评论 0原文

我有一个 Core Data 应用程序,最终将成为 iPhone/iPad 通用应用程序。

我想实现云同步,以便运行该应用程序的 iPhone 和 iPad 可以共享数据。我计划使用最近发布的 Dropbox API。有人对执行此操作的最佳方法有任何想法吗? Dropbox API 允许应用程序在云上存储文件。我的想法是最初将应用程序的数据库(sqlite)存储在云上,然后下载该数据库,但后来我意识到使用该方法将使合并更改(而不是替换整个数据库)变得非常困难。

任何想法表示赞赏。谢谢。

I have a Core Data app that will end up being an iPhone/iPad universal application.

I would like to implement cloud syncing so that an iPhone and an iPad both running the app could share data. I'm planning to use the recently released Dropbox API. Does anyone have any thoughts on the best way to go about doing this? The Dropbox API allows for apps to store files on the cloud. What I was thinking was to original store the database (sqlite) for the app on the cloud and then download that database, but I then realized that using that method would make it painfully difficult to merge changes (rather than replacing the whole database).

Any thoughts are appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦归所梦 2024-09-10 14:15:41

如果您能逃脱惩罚,那么(到目前为止)最简单的同步方法是在本地拥有数据的三个副本:您上次上传的副本(“旧”)、由本地更改(“我的”)和从服务器下载的副本(“他们的”)现在

然后,对所有三个文件中的所有记录进行排序,并逐一浏览它们:

  • 如果旧 == 我的,使用他们的
  • ,否则如果旧 == 他们的,使用我的
  • ,否则你有冲突;对此做点什么(例如,总是使用我的,又名“最后一个作家获胜”)

请注意,“我的”或“他们的”或“旧的”可能不存在。上述规则在此情况下仍然适用;如果您选择的结果是“不存在”,那么您将需要删除输出文件中的记录。

最后,将生成的文件上传回服务器,以便它将成为下一个人的“他们的”数据库。然后将新文件复制到本地“旧”和“我的”数据库。

(有比上述更节省空间的算法......但没有任何更简单的算法:)并且磁盘空间现在非常便宜,特别是如果您压缩文件。)

If you can get away with it, the easiest way to do synchronization (by far) is to have three copies of your data locally: the copy you last uploaded ("old"), the copy produced by local changes ("mine") and the copy now downloaded from the server ("theirs").

Then, sort all the records in all three files and walk through them one by one:

  • if old == mine, use theirs
  • else if old == theirs, use mine
  • else you have a conflict; do something about it (eg. always use mine, aka "last writer wins")

Note that "mine" or "theirs" or "old" might not exist. The rules above still apply in that case; if the result you choose is "does not exist", then you'll want to delete the record in the output file.

Finally, upload the resulting file back to the server so that it will be the "theirs" database for the next guy. Then copy the new file to your local "old" and "mine" databases.

(There are more space-efficient algorithms than the above... but there aren't any easier ones :) And disk space is pretty cheap nowadays, particularly if you compress the files.)

日记撕了你也走了 2024-09-10 14:15:41

您可能想要使用不同的同步方法。您将处理什么类型的数据?

我使用轻量级 Rails 后端取得了很大成功。

You may want to use a different method for synchronization. What is the type of data that you will be dealing with?

I've had much success using a lightweight rails back-end.

撞了怀 2024-09-10 14:15:41

您可以查看 GameKit共享数据。否则,您似乎只需要管理与中间文件服务器的同步。

You might look into GameKit to share data. Otherwise it seems like you'll just need to manage synchronization with an intermediate file server.

蘑菇王子 2024-09-10 14:15:41

您可能希望将数据导出为本机 sqlite 格式以外的某种格式。如果我要设计这样的东西,我认为 JSON 可能是我选择的格式。

我没有看过dropbox API,但它们支持上传和下载文件差异,而不是整个文件,对吧?根据 API 的工作方式,也许让您的应用程序理解它们的“diff”格式并使用它可能会更容易......

You probably want to export the data to some format other than the native sqlite format. If I were designing something like this, I think JSON would probably be my format of choice.

I haven't looked at the dropbox API, but they support uploading and downloading file differences, rather than the whole file, right? Depending on how the API works, maybe having your application understand their "diff" format and working with that might be easier...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文