Take the 2-minute tour ×

I'm running the following example code from Apple -

        NSString *requestURL = [[NSString alloc] initWithString:@"http://google.com/"];         
        NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:requestURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
        NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

        if(theConnection) {

            NSLog(@"The connection has started...");

        } else {

            NSLog(@"Connection has failed...");


But the delegate methods below aren't being called. Can anyone please help me out?

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

If you are performing this on a background thread, the thread is probably exiting before the delegates can be called. Look at calling in your method that starts the transfer just after you call the method that fires off the background thread, CFRunLoopRun(). Then in your callbacks connectionDidFinishLoading: and connection:didFailWithError: make sure you also run:


At the end of those methods, otherwise you will never return.

share|improve this answer
add comment

Are you setting the delegate? In the class interface where that code is located, add <NSURLConnectionDelegate>

For example:

@interface myClass : parentClass<NSURLConnectionDelegate>

Good luck!

share|improve this answer
add comment

Your Answer


