I'm creating an NSURLConnection
but using an invalid URL (http://thiswontwork.com/asdf). I'm calling it on the main thread and I've implemented all of the delegate methods in my delegate.
The connection hangs and never calls any of the delegate methods, I would have expected connection:didFailWithError:
to be called. The only delegate method called is
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
Has anyone come across anything like this?
Happens under debugger on device and in simulator (iOS5 on xCode4).
Have created a trivial view controller with single button example to demonstrate, can post code if required.
Timeout interval is being set on the request (to 30 secs).
If you return nil the connection is finished. I'm not in front of the docs right now but I believe it's standard practice to return the NSURLRequest
passed into the function. Something like:
-(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response{
return request;
}
Edit
After looking at the documentation I see what you mean. The documentation is extremely misleading as to what will happen if you return nil. It says if you return nil the connection will continue but I believe that this is only in the case where response
is not nil. I tested returning nil in a small download manager project I had written and it seemed to stall the connection out completely.
This would seem to either be a bug or an instance of poor documentation.