views:

327

answers:

1

It seems dead simple, as to create an NSURLConnection I usually do this:

NSURL *theURL = [NSURL URLWithString:urlString];
NSURLRequest *req = [NSURLRequest requestWithURL:theURL];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:req delegate:self];

But how can I get the URL back in the delegate methods? Short of hanging on to them myself (I'm running many connections at once, so this becomes slightly messy). It seems as though I should be able to get the URL back from a connection.

Am I missing something?

+7  A: 

In -connection:didReceiveResponse: you can get the URL. Note that this may not be the same URL you created the connection with since the connection may have been redirected.

- (void)connection:(NSURLConnection *)connection 
            didReceiveResponse:(NSURLResponse *)response {
    NSURL * url = [response URL]; // The URL
}
Cory Kilger