7

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.

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)?

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).

4

1 回答 1

3

以下是我将如何处理这个问题:

  1. 首先对反映在线数据库的本地 CoreData/Sqlite 数据库进行建模。
  2. 将 NSDate lastModified 属性添加到每个表的每一行。这将允许我在记录级别而不是字段级别跟踪更改。这有助于降低同步复杂性,并且在大多数现实世界的场景中,记录级同步就足够了。
  3. 应用程序启动时执行自动同步,并在导航栏中提供突出的“同步”按钮。这样,当应用程序在很长一段时间后启动时,用户始终拥有更新的数据集,并且可以同步一天中的最新更改。我会避免在使用应用程序时进行后台同步。当您尝试处理其他事情时,这将使您的应用程序更加复杂且容易出错。所以推迟后台/自动同步的工作,直到你有剩下的工作。
  4. 一旦我的同步在启动和按需时工作得相当好,我会尝试支持后台同步。我还会尝试消除“同步”按钮,这样用户就不必考虑同步 - (就用户而言,它始终是最新的)。但这将是一个长期的增强,只有在我“按需”同步工作坚如磐石之后,我才会尝试。

希望这可以帮助您入门。如果您对此有不同的看法,我很想听听。

于 2012-05-21T03:23:12.110 回答