Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURL from NSURLConnection?

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?

like image 797
jbrennan Avatar asked Jan 22 '23 09:01

jbrennan


1 Answers

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
}
like image 85
Cory Kilger Avatar answered Jan 29 '23 09:01

Cory Kilger