如何将 iPhone Core Data 与 Web 服务器同步,然后推送到其他设备? [英] How to Sync iPhone Core Data with web server, and then push to other devices?

查看:27
本文介绍了如何将 iPhone Core Data 与 Web 服务器同步,然后推送到其他设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究一种在多个设备(例如 iPad 或 Mac)之间同步 iPhone 应用程序中存储的核心数据的方法.在 iOS 上使用 Core Data 的同步框架并不多(如果有的话).不过,我一直在思考以下概念:

I have been working on a method to sync core data stored in an iPhone application between multiple devices, such as an iPad or a Mac. There are not many (if any at all) sync frameworks for use with Core Data on iOS. However, I have been thinking about the following concept:

  1. 对本地核心数据存储进行了更改,并保存了更改.(a) 如果设备在线,它会尝试将变更集发送到服务器,包括发送变更集的设备的设备 ID.(b) 如果变更集没有到达服务器,或者如果设备不在线,应用程序会将变更集添加到队列中,以便在它上线时发送.
  2. 位于云端的服务器将收到的特定更改集与其主数据库合并.
  3. 在云服务器上合并变更集(或变更集队列)后,服务器使用某种轮询系统将所有这些变更集推送到向服务器注册的其他设备.(我想使用 Apple 的 Push 服务,但显然根据评论这不是一个可行的系统.)

有什么奇特的事情需要我考虑吗?我看过 REST 框架,例如 ObjectiveResource核心资源,以及RestfulCoreData.当然,这些都与 Ruby on Rails 一起工作,我不依赖于它,但它是一个起点.我对解决方案的主要要求是:

Is there anything fancy that I need to be thinking about? I have looked at REST frameworks such as ObjectiveResource, Core Resource, and RestfulCoreData. Of course, these are all working with Ruby on Rails, which I am not tied to, but it's a place to start. The main requirements I have for my solution are:

  1. 任何更改都应在后台发送,而不要暂停主线程.
  2. 它应该使用尽可能少的带宽.

我考虑了一些挑战:

  1. 确保不同设备上不同数据存储的对象 ID 附加到服务器上.也就是说,我将有一个对象 ID 和设备 ID 表,它们通过对存储在数据库中的对象的引用绑定.我将有一个记录(DatabaseId [此表唯一]、ObjectId [整个数据库中的项目唯一]、Datafield1、Datafield2),ObjectId 字段将引用另一个表 AllObjects: (ObjectId, DeviceId, DeviceObjectId).然后,当设备上推一个变更集时,它会传递设备 ID 和来自本地数据存储中的核心数据对象的 objectId.然后我的云服务器会对照AllObjects表中的objectId和deviceId,在初始表中找到要改变的记录.
  2. 所有更改都应加上时间戳,以便合并.
  3. 设备必须轮询服务器,而不会消耗太多电池.
  4. 如果/当从服务器收到更改时,本地设备还需要更新内存中保存的任何内容.

这里还有什么我遗漏的吗?我应该考虑什么样的框架才能实现这一点?

Is there anything else I am missing here? What kinds of frameworks should I look at to make this possible?

推荐答案

我建议仔细阅读并实施 Dan Grover 在 iPhone 2009 会议上讨论的同步策略,可在 此处 作为 pdf 文档.

I suggest carefully reading and implementing the sync strategy discussed by Dan Grover at iPhone 2009 conference, available here as a pdf document.

这是一个可行的解决方案,实施起来并不困难(Dan 在其几个应用程序中实现了这一点),与 Chris 描述的解决方案重叠.有关同步的深入理论讨论,请参阅 Russ Cox(麻省理工学院)和 William Josephson(普林斯顿大学)的论文:

This is a viable solution and is not that difficult to implement (Dan implemented this in several of its applications), overlapping the solution described by Chris. For an in-depth, theoretical discussion of syncing, see the paper from Russ Cox (MIT) and William Josephson (Princeton):

矢量时间对的文件同步

这同样适用于经过一些明显修改的核心数据.这提供了一种整体上更加强大和可靠的同步策略,但需要付出更多努力才能正确实施.

which applies equally well to core data with some obvious modifications. This provides an overall much more robust and reliable sync strategy, but requires more effort to be implemented correctly.

似乎 Grover 的 pdf 文件不再可用(断开的链接,2015 年 3 月).更新:该链接可通过 Way Back Machine 这里

It seems that the Grover's pdf file is no longer available (broken link, March 2015). UPDATE: the link is available through the Way Back Machine here

由 Marcus Zarra 开发的名为 ZSync 的 Objective-C 框架已被弃用,因为 iCloud 最终似乎支持正确的核心数据同步.

The Objective-C framework called ZSync and developed by Marcus Zarra has been deprecated, given that iCloud finally seems to support correct core data synchronization.

这篇关于如何将 iPhone Core Data 与 Web 服务器同步,然后推送到其他设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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