I have two request starting one after the other. Starting request like this
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com"]];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
NSURLConnection * connection = [[NSURLConnection alloc]
initWithRequest:request
delegate:self startImmediately:NO];
[connection scheduleInRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
[connection start];
and another request starting like this.
NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.apple.com"]];
NSURLRequest *request1 = [NSURLRequest requestWithURL:url1 cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
NSURLConnection *connection1 = [[NSURLConnection alloc] initWithRequest:request1 delegate:self];
[connection1 release];
How can i differentiate between these two in delegate method?
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{}
Don't want to keep any extra class variable for this purpose.
It's Simple :
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if (connection == connection1)
{
//It's for connection1.
}
else if (connection == connection2)
{
//It's for connection2.
}
}
You can go through this Beautiful SO Question : Managing multiple asynchronous NSURLConnection connections
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With