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

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

问题描述

我一直在使用一种方法来同步存储在iPhone应用程序中的多个设备(如iPad或Mac)之间的核心数据。没有太多(如果有的话)同步框架与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. 在云服务器上合并更改集(或更改集队列)后,可以在云服务器上合并其特定更改集。服务器使用某种轮询系统将所有这些更改集推送到向服务器注册的其他设备。 (我认为使用苹果的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. 它应该使用尽可能少的带宽。

我已经考虑了一些挑战: / p>

I have thought about a number of the challenges:


  1. 确保不同设备上不同数据存储的对象ID连接在服务器上。也就是说,我将有一个对象ID和设备ID的表,它们通过对存储在数据库中的对象的引用来绑定。我将有一个记录(DatabaseId [该表独有],ObjectId [对整个数据库中的项唯一],Datafield1,Datafield2),ObjectId字段将引用另一个表,AllObjects:(ObjectId,DeviceId,DeviceObjectId)。然后,当设备推送更改集时,它将沿着设备Id和来自本地数据存储中的核心数据对象的objectId传递。然后,我的云服务器将检查AllObjects表中的objectId和设备ID,并找到要在初始表中更改的记录。

  2. 所有更改都应加时间戳,

  3. 设备将必须轮询服务器,而不占用太多电池。

  4. 本地设备还需要更新任何保留

  1. Making sure that the object IDs for the different data stores on different devices are attached on the server. That is to say, I will have a table of object IDs and device IDs, which are tied via a reference to the object stored in the database. I will have a record (DatabaseId [unique to this table], ObjectId [unique to the item in the whole database], Datafield1, Datafield2), the ObjectId field will reference another table, AllObjects: (ObjectId, DeviceId, DeviceObjectId). Then, when the device pushes up a change set, it will pass along the device Id and the objectId from the core data object in the local data store. Then my cloud server will check against the objectId and device Id in the AllObjects table, and find the record to change in the initial table.
  2. All changes should be timestamped, so that they can be merged.
  3. The device will have to poll the server, without using up too much battery.
  4. The local devices will also need to update anything held in memory if/when changes are received from the server.

我在这里缺少什么吗?

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(MIT)和William Josephson(Princeton)的论文:

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月)。 UPDATE:链接可通过后退机 here

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

Objective-C框架名为 ZSync 并由Marcus Zarra开发的已经被弃用,因为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核心数据与Web服务器,然后推送到其他设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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