4

I have a few UITableViews that gather their content from remote XML files. Sometimes the file is updated, but the view is not updated, because I load the file in my viewDidLoad method.

I am assuming I should do a check in viewDidAppear and load my XML file again. But I don't want it loading every time the user clicks back to that view.

What is the best way to do this? Can I somehow check the updated date of a remote file on the web? Or should I store the updated date in my app, then check at an interval? There must be a preferred way to do this, so that I know that the XML file has been updated.

Thanks.

Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
  • I don't know if there's a "preferred way," as every application has its own set of requirements. Is this a live feed of data, where the update is essential? Or can it be delayed? Is there a reason you can't use the server provided cache-control, and determine when to reload the data based on that? – joshpaul Apr 15 '11 at 18:33

5 Answers5

0

You need to send simple request from application (maybe by timer event), which will ask server about updates. If your content on server was updated then you need to reload your content in application.
You can track changes time on server and latest content update time in application.

Artem Shmatkov
  • 1,434
  • 5
  • 22
  • 41
0

I suggest making a get request to a page that has a very small overhead with only the data you need to check whether the version has changed.

On the iOS app, store the last version value you stored and check it against this small page you pull. If the value on the page is greater (newer) then pull the full XML file.

This version value could either be the datetime it was updated or the version number. I am not on a Mac at the moment so testing Obj-C code isn't trivial, but here's some pseudocode:

int versionNumber; // can be a datetime as well
...
void pullXmlIfAvailable() {
    int latestVersionNumber = parseVersionNumberFromPage(URLget("myurl.com/check.xml")).to_i();

    if (latestVersionNumber > versionNumber)
        DataClass xml = parseDataFromLargerFile(URLget("myurl.com/bigfile.xml"));
}
AndrewKS
  • 3,603
  • 2
  • 24
  • 33
0

Perhaps you could load fresh data right as your application is brought to the background(detected in your app delegate).

an option for this:

  • Keep your data object in your app delegate class and reference it in the controller containing your UITableView. When your view controller calls viewDidAppear, just call your reloadData of your UITableView.
james
  • 26,141
  • 19
  • 95
  • 113
0

Instead of asking the server for a version number or update-date, why not telling the server the version number or update-date of your remote (client-based) version.

Your server then decides if you have a recent version already (A) or if you need a new one (B):

Till
  • 27,559
  • 13
  • 88
  • 122
0

The other answers have already covered "when should I reload" the file quite well.

One other thing to consider is using the "pull to refresh" metaphor that's very common in tableview apps these days, as it gives users a way to both seen when the data was last updated and to request it's immediately updated.

See iPhone Pull Down Refresh like Tweetie for some libraries that make implementing it pretty straight forward.

Community
  • 1
  • 1
JosephH
  • 37,173
  • 19
  • 130
  • 154