As far as I know, the connection object is always created. Even your URL is incorrect. Any errors come to the didFailWithError delegate didFailWithError . You probably need to check the error and continue it accordingly. Ex. In case this is a timeout, you can try again in the didFailWithError didFailWithError . For other types of errors, they are handled differently.
If you want to handle broken or bad URLs before submitting them to NSURLConnection , you need to do it yourself.
Here are the delegates that you, when using NSURLConnection -
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSLog("@Resp received"); return; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSLog("@Data received"); return } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog("@ERROR: Achtung !: %@",[error localizedDescription]); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH , 0),, ^{ NSLog(@"FinishedLoading: In bg thread, do something with data here"); dispatch_async( dispatch_get_main_queue(), ^{ NSLog(@"FinishedLoading: In Main thread, access the UI here"); }); }); }
source share