views:

64

answers:

2

Hey,

I have an .xml file that is going to be shipped within my app. This file contains values that are read from it and saved as an array when the app launches.

Each time the app is run, I want to check with the server if there is an internet connection. If so, I want to get the newest version of the .xml file from the server and replace the one that I currently have saved in my app (this way, the next time the user logs in and doesn't have internet access, he/she will be able to use the old (yet most up to date) data).

What is the best way to do this?

Thanks,

+4  A: 

The best way to probably do this is to copy the XML file from the app bundle to a location in the app's sandbox, e.g. the Documents folder. Thereafter you can update the XML content as necessary with newer data from the server. The copy is necessary to allow you to write to the file, since you cannot change the content of your app's bundle because it is signed.

Alternatively, if the data is simple enough, you can just save it to user defaults on first launch and change the defaults on subsequent updates

nduplessis
A: 

I might skip the XML altogether, unless it contains a baseline of default settings, and just sync user defaults over the Internet. You can't modify files in the bundle, so your only option would be to copy over a "default-settings" XML file to the application's Documents folder to make it editable.

Alex Reynolds