Currently my app pulls data from an Microsoft SQL 2005 database via ASP.NET XML web services using SOAP whenever it needs data.
I would like to change my app so that it has a local database, and this database would check to see if the data has changed and synch itself to any new data.
How do i tell if there is any new data?
Do i just count the number of rows in the SQL table and if it less than the number of rows in the CoreData database then re-write the CoreData database?
Is there a way to tell only sync the records that have changed or been added/deleted?
Should i be synching all data when the app starts or synching only the table that corresponds to the loading view?
Any help is greatly appreciated!
Thanks,
-Mike
If you are clever with your schema design than you can. The best option is probably to add ‘created_at’ and ‘updated_at’ date fields to your database tables (and set them whenever you modify or create records). Then in your sync request query, select all records that have a date greater than the highest date in your local database. This will work for a ONE way synchronization. TWO way synchronization is much more difficult and requires thought on contact resolution.
As for syncing, I’d recommend doing it in the background whenever possible. You should be able to use the
NSFetchedResultsControllerto handle updating your views when new records are fetched. This way the user won’t experience any annoying loading screens.