iOS应用程序 - 用于使CoreData与Web服务同步的架构/示例 [英] iOS app - architecture/sample for synchronizing CoreData against Web-Service

查看:143
本文介绍了iOS应用程序 - 用于使CoreData与Web服务同步的架构/示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个示例应用程序或更多的架构讨论来构建一个应用程序,它维护一个本地持久化存储(CoreData),并保持同步的Web服务,如Flickr。在我的例子是Salesforce,但模式应该类似于许多应用程序Flickr,Twitter,IMAP等。

I am looking for either a sample app or a more architectural discussion to build an app, which maintains a local persistent store (CoreData) and keeps it sync against a Web-Service like Flickr. In my case it is Salesforce, but the pattern should be similar to many apps for Flickr, Twitter, IMAP and so on.

示例问题:
其中最好的点调用同步?
什么是已证明的数据结构以维护本地更改
- 为每个未同步的更改在本地存储中维护已更改BOOL;我更喜欢一个字段级标志对记录级标志)?

Sample questions: where are the best points to invoke the syncing? what are proven datastructures to maintain local changes - maintain a "changed" BOOL in the local store for every unsynched change; I would prefer a field level flag against a record level flag)?

当然,我必须自己优化,知道记录(100的)的数量和更改(每天10次)和冲突的概率(在我的情况下在字段级别上低)。

Of course I have to optimize this on my own, knowing the amount of records (100's) and changes (10's per day) and the probability of conflicts (low in my case on a field level).

推荐答案

方法:


  1. 首先建立一个镜像您的在线数据库的本地CoreData / Sqlite数据库。

  2. 为每个表的每一行添加一个NSDate lastModified属性。这将允许我跟踪记录级别的更改,而不是字段级别。这有助于降低同步复杂性,在大多数真实情况下,记录级别同步就足够了。

  3. 在应用启动时执行自动同步,并在您的导航栏。这样,当应用程序在长时间后启动时,用户始终拥有更新的数据集,并且可以在一天内同步最新的更改。我会避免做应用程序使用时的背景同步。这将使你的应用程序更复杂和容易出错,当你试图解决其他的事情。

  4. 一旦我在启动和点播时我的同步工作相当顺利,我将尝试并支持后台同步。我也会尝试消除同步按钮,所以用户从来不必考虑同步 - (它始终是最新的,就用户而言)。但是这将是一个长期的增强,我只有在按需同步工作的摇滚坚固后才会尝试。

  1. Start by modeling a local CoreData/Sqlite database that mirrors your online database.
  2. Add an NSDate lastModified property to every row of each table. This will allow me to track changes at the record level, instead of field level. This helps reduce sync complexity, and in most real world scenarios, record level syncing is sufficient.
  3. Perform an automatic sync when the app starts, and also provide a prominent "Sync" button in your navigation bar. This way the user always has an updated dataset when the app launches after a long period, and can sync the latest changes over the course of a day. I would avoid doing background sync while the app is being used. This will make your app more complex and error-prone when you're trying to tackle other things. So postpone working on background/automatic sync until you have the rest working.
  4. Once I have my sync working reasonably well at launch and on-demand, I would try and support background sync. I would also try and eliminate the "Sync" button, so the user never has to think about syncing - (it's always up to date as far as the user is concerned). But this would be a longer term enhancement, which i would attempt only after I have "on-demand" syncing working rock solid.

希望这有助于你开始。我很愿意听到,如果你对此有任何不同的看法。

Hope this helps you get started. I would love to hear if you think differently about any of this.

这篇关于iOS应用程序 - 用于使CoreData与Web服务同步的架构/示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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