views:

372

answers:

2

My app is highly data driven, and needs to be frequently updated. Currently the MySQL database is dumped to an xml file via PHP, and when the app loads it downloads this file. Then it loads all the values in to NSMutableArray's inside of a data manager class which can be accessed anywhere in the app.

Here is the issue, the XML file produced is about 400kb, and this apparently takes several minutes to download on the EDGE network, and even for some people on 3G. So basically I'm looking for options on how to correctly cache or optimize my app's download process.

My current thought is something along the lines of caching the entire XML file on to the iPhone's hard disk, and then just serving that data up as the user navigates the app, and loading the new XML file in the background. The problem with this is that the user is now always going to see the data from the previous run, also it seems wasteful to download the entire XML file every time if only one field was changed.

TLDR: My iPhone app's download of data is slow, how would one properly minimize this effect?

+1  A: 

My suggestion would be to cache the data to a SQLite database on the iPhone. When the application starts, you sync the SQLite database with your remote database...while letting the user know that you are loading incremental data in the background.

By doing that, you get the following:

  1. Users can use the app immediately with stale data.
  2. You're letting the user know new data is coming.
  3. You're storing the data in a more appropriate format.

And once the most recent data is loaded...the user gets to see it.

Justin Niessner
This is something I'd like to consider as well. It has the added bonus of leveraging the iPhone's core data framework. The only problem is that it's a for-pay job where there is very low tolerance to risk, and I have never used Core Data. The client wants the option that can be set up in a short amount of time, which is probably just to save the XML file to disk, (would not have to rewrite the code to populate arrays, and show it in the relevant pieces of the app.)
Jameson
+2  A: 

I've had to deal with something like this in an app I developed over the summer.

I what did to solve it was to do an initial download of all the data from the server and place that in a database on the client along with a revision number.

Then each time the user connects again it sends the revision number to the server, if the revision number is smaller than the server revision number it sends across the new data (and only the new data) from the server, if its the same then it does nothing.

It's fairly simple and it seems to work pretty well for me.

This method does have the drawback that your server has to do a little more processing than normal but it's practically nothing and is much better than wasted bandwidth.

James Raybould