Yes, the completion handler is always called. If the request fails due to a timeout, the error
will be set and data = nil
.
A NSURLRequest
has a default timeout of 60 seconds, but you can assign a different value to request.timeoutInverval
before starting the connection. So there is no need for an extra timer.
Added: In the case of a timeout:
[error domain]
isNSURLErrorDomain
, and[error code]
isNSURLErrorTimedOut
,
If you just want to present an error message, you can use [error localizedDescription]
, which is "The request timed out." in this case. (This may depend on the locale.)