Does anyone know in which situations initializing a NSURLConnection
returns nil instead of the created connection. The documentation says it's possible but fails to specify when this happens.
The method/message in question:
[[NSURLConnection alloc] initWithRequest:request delegate:self];
-
According to the NSURLConnection
Class Reference:
Return Value: The URL connection for the URL request. Returns nil if a connection can't be initialized.
The URL Loading System Programming Guide says the following:
If NSURLConnection can’t create a connection for the request, initWithRequest:delegate: returns nil.
-
While it's possible that this method returns nil, I'm unable to come up with a scenario which triggers this. I've tried the following scenarios:
URLRequest
with an empty url:connection:didFailWithError:
delegate method is called with "unsupported URL" as error.URLRequest
with invalid url:connection:didFailWithError:
delegate method is called with "bad URL" as error.URLRequest
with nonexistent url:connection:didFailWithError:
delegate method is called with "A server with the specified hostname could not be found." as error.- Valid request but no internet:
connection:didFailWithError:
delegate method is called with "The Internet connection appears to be offline." as error. - nil request: causes a crash.
The initWithRequest
method returned a valid NSURLConnection
in each scenario (besides the last one) and called the connection:didFailWithError:
with an appropriate error.
Has anybody been able to figure out which scenario does cause nil to be returned?