iOS app - architecture/sample for synchronizing CoreData against Web-Service

久未见 提交于 2019-12-04 21:31:13

问题


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


回答1:


Here's how I would approach this:

  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.



来源:https://stackoverflow.com/questions/10207539/ios-app-architecture-sample-for-synchronizing-coredata-against-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!