views:

33

answers:

1

I have an app which gets some data from the web via an XML document. I have this working fine and have followed apples SeismicXML example (uses NSURLRequest etc). I am very new to this so I have to admit that I do not totally understand all the code that gets the XML - but it is working. My problem is that my app may be running for some time so I want to be able to refresh the XML every now and again and check to see if it is different. If it is different I need to update my contents. Basically this means my questions are....

  1. Is there a standard way of doing this?
  2. I was thinking of creating a timer to call the function which parses the XML but I can't figure out which function to call.

If anyone can give me any pointers or even better examples of this it would be fab. Thanks

A: 

An NSTimer is the way to kick off a process that needs performing every x seconds

[NSTimer scheduledTimerWithTimeInterval:5 
                                 target:self 
                               selector:@selector(theXMLMethod)
                               userInfo:nil
                                repeats:YES];

This sets a timer of 5 seconds that calls the theXMLMethod method.

James Raybould
"An NSTimer *with a `scheduledTimerWithTimeInterval:`* is the way .."
Emil
Since the download may take longer than 5 seconds in some cases, you probably want a non-repeating timer that you reset every time the download operation finishes or fails.
alltom
That's great thanks :-)