Reputation: 9180
I have successfully created a Cocoa app that uses NSXMLParser to retrieve data from an online XML file. Now I am trying to figure out how to automatically refresh the XML data.
Here are some of the relevant methods in my implementation file:
- (void)awakeFromNib {
NSURL *xmlURL = [NSURL URLWithString:@"my_url_here"];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[parser setDelegate:self];
[parser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
}
So how can I automatically refresh the XML every 15 minutes?
Upvotes: 0
Views: 735
Reputation: 1073
Check out NSTimer with a repeating interval
Example to call a method called getMessage every 15 minutes (900 seconds):
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:900
target:self
selector:@selector(getMessage:)
userInfo:nil repeats:YES];
self.repeatingTimer = timer;
Upvotes: 1