Skip to content

Commit

Permalink
made fetching places async
Browse files Browse the repository at this point in the history
  • Loading branch information
phuesler committed Dec 11, 2009
1 parent 6143a4f commit db07c44
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions HallenprojektStatusAppDelegate.m
Expand Up @@ -40,24 +40,28 @@ - (void) setStatusIcon {

}

- (void)fetchingPlacesFinished:(ASIHTTPRequest *)request {
NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"the places"] autorelease];
SBJSON *parser = [[SBJSON alloc] init];
NSString *json_string = [[NSString alloc] initWithString:[request responseString]];
NSArray *places = [parser objectWithString:json_string error:nil];
[self addItemsToMenu:menu fromDictionary:[places objectAtIndex:0]];
[self addItemsToMenu:menu fromDictionary:[places objectAtIndex:1]];
[placesMenuItem setSubmenu:menu];
}

- (void)fetchingPlacesFailed:(ASIHTTPRequest *)request
{
NSLog(@"%@",[[request error] localizedDescription]);
}

- (void) fetchPlaces {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HALLENPROJEKT_SERVER,@"places.json"]];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request start];
NSError *error = [request error];
if (!error) {
NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"the places"] autorelease];
SBJSON *parser = [[SBJSON alloc] init];
NSString *json_string = [[NSString alloc] initWithString:[request responseString]];
NSArray *places = [parser objectWithString:json_string error:nil];
[self addItemsToMenu:menu fromDictionary:[places objectAtIndex:0]];
[self addItemsToMenu:menu fromDictionary:[places objectAtIndex:1]];
[placesMenuItem setSubmenu:menu];

}
else {
NSLog(@"%@",[error localizedDescription]);
}
[request setDelegate: self];
[request setDidFinishSelector:@selector(fetchingPlacesFinished:)];
[request setDidFailSelector:@selector(fetchingPlacesFailed:)];
[request startAsynchronous];
}


Expand Down

0 comments on commit db07c44

Please sign in to comment.