Reputation: 3852
if i use ASIHTTPRequest the first time , with asynchroun mode , i recive result and error in
- (void)requestFinished:(ASIHTTPRequest *)request and the error in
- (void)requestFailed:(ASIHTTPRequest *)request
but what if I make another query asynchronously? I will receive the result in the same method? how to know if this is the result of the first query or second? I tryed to change the delegate but it don't work
-(void)getCities
{
NSString * myURLString = [NSString stringWithFormat:@"http://localhost:8080/Data/resources/converter.city/CountryCode/%@",choosedCodeCity];
NSURL *url =[NSURL URLWithString:myURLString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:resultCities];
[request startAsynchronous];
}
-(void)resultCities :(ASIHTTPRequest *)request
{
}
Upvotes: 0
Views: 179
Reputation: 4805
ASIHttpRequest has a NSDictionary* userInfo
property that you can use to store whatever you like. You can simply add a flag to this dictionary in order to tell the two requests apart.
Another approach would be to use the ASIHttpRequest methods that take blocks instead of using a delegate.
EDIT: To use the flag approach, when you create the request object, do something like
[request.userInfo setObject:[NSNumber numberWithInt:1] forKey:@"flag"];
Then in the response methods you can ask the request for the flag to determine which request it is.
int flag = [[request.userInfo objectForKey:@"flag"] intValue];
Upvotes: 1
Reputation: 16714
you can do:
request.didFinishSelector = @selector(yourFinishMethodHere:);
request.didFailSelector = @selector(yourFailMethodHere:);
in other words, you do not have to use the default "requestFinished:" and "requestFailed:" methods on the delegate.
Upvotes: 1