As mentioned in others and in my comment, there are a few bugs in your code which you need to fix.
But there is also one big misconception - stemming from the former awful documentation of NSURLConnection
:
connectionDidFinishDownloading:destinationURL:
is NOT a delegate method of the two delegates of NSURLConnection namely, NSURLConnectionDelegate
and NSURLConnectionDataDelegate
which you are supposed to implement in your case.
The minimal set of delegate methods you need to implement are:
For the NSURLConnectionDelegate
:
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
then for the NSURLConnectionDataDelegate
:
(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
(void)connectionDidFinishLoading:(NSURLConnection*)connection;
If you don't mind, I've put a sample of a minimal implementation on Gist: SimpleGetHTTPRequest which should give you a jump start do implement your own HTTP request class.