views:

38

answers:

2

Hi,

I'm developing an iPhone app that relies heavily on calling ASP.NET Webservices to transfer data to and fro between a database in one of our servers and the phone.

There are multiple items that the user works on. And to work on each item, a typical usecase requires 5-6 webservice calls. Depending on 3G signal strengths, the amount of data that's being downloaded and the number of items each day, it takes any where between 5-6 minutes of time just to keep the user looking at the spinning wheel.

This is simply not acceptable, so, basically I want to be able to asynchronously keep both the app and the database on the server side in sync.

How would I go about doing this? (I'm currently not using CoreData at all, but I'm guessing I probably need to use it now).

Thanks,
Teja

A: 

Hmm let's see. You're writing an iPhone application that will talk to a .NET web service? That's a bit like driving a Ferrari and trying to park it in a busted-down garage on the dodgy end of town, isn't it?

Wilhelm VonScharrtenburg
It's more of a company choice. All the db access wrappers are written, and it's expressly forbidden to access them in any other way.Anyway, is there a problem with .NET webservices? If you look at just the performance, there doesn't seem to be too much of an issue.
Tejaswi Yerukalapudi
this is just plain irrelevant
davidsleeps
+1  A: 

You will need to code the glue beteeen core data and your restful web service. Try and design your data model to match the data coming back from the web service and that will make the glue easier to manage. If you can get the data in JSON then the glue will be even less.

Core Data is an object hierarchy and you will need to approach it like that when you design your caching and syncing code.

Update

The tableview has nothing to do with the data. When you are working with Objective-C and iOS you need to think in terms of MVC. So you need to be thinking about watching delta changes in your Model (the UI or view portion of MVC is irrelevant). Core Data easily lets you do this during a save operation and you can take those deltas and push them back up to the server. The tricky issue is how to get notifications from the server of changes server side. That is something that is dependent on the server design.

Processing changes from the server should be done on a background thread (with a separate NSManagedObjectContext connected to the same NSPersistentStoreCoordinator) and the main thread should be watching for save notifications from that background thread so that it can update the UI as needed.

This is a non-trivial design and the complexity means that you can and will run into issues but those issues are dependent on your application and server design. There is no silver bullet other than the fact that using Core Data makes all of this a lot easier.

Marcus S. Zarra
Thanks for the reply! What sort of problems will I encounter when writing the mapping part? I'm slightly worried about having to write lock/unlock code for my model when updating it asynchronously.I know the general theory behind semaphores/mutexes, but I have never implemented anything that's practical that uses them.Also, can you give a highlevel overview of such a system? (Say 1 screen with a table view for which the data is updated async)
Tejaswi Yerukalapudi
Edited answer based on your additional questions.
Marcus S. Zarra
Sorry, the model is what I meant. Assuming we have an array as datasource for a tableview, and I need to update that array, while the user might access that view at the same time.I probably need to do some actual implementation. I'll get back once I have a better picture of the problem.Thanks!
Tejaswi Yerukalapudi
Use a `NSFetchedResultsController` instead of an array to be the datasource for the table view. Then the table view will get updated automatically whenever the attached `NSManagedObjectContext` has changed in a meaningful way.
Marcus S. Zarra