NSURLSession
offers two timeouts, timeoutIntervalForRequest
and timeoutIntervalForResource
.
timeoutIntervalForRequest
is enforced by a timer that is reset every time data is transferred. So if you set this timeout to 30 seconds and at least one byte of data is transferred every 30 seconds, the timeout is never hit. The timeout is only hit if absolutely no data is transferred for 30 seconds. You could also say that this is the maximum idle time for a session task. The default value is 60 seconds.
timeoutIntervalForResource
is enforced by a timer that is never reset. It is started when a session task is started and it is stopped when a session task is stopped or has finished. So this is the maximum total amount of time a session task can take and this is what most people think of, when they hear "timeout". As a session task may also be a download of a 100 GB file over a very slow Internet link, the default value here is 7 days!
NSURLRequest
(and its mutable subclass) offers only one property timeoutInterval
. This timeout value behaves like timeoutIntervalForRequest
as the documentation of NSURLRequest
says:
If during a connection attempt the request remains idle for
longer than the timeout interval, the request is considered
to have timed out.
Source: timeoutInterval - NSURLRequest | Apple Developer Documentation
And the documentation of NSURLSession
says:
Note
In some cases, the policies defined in this configuration may be
overridden by policies specified by an NSURLRequest object provided
for a task. Any policy specified on the request object is respected
unless the session’s policy is more restrictive.
Source: NSURLSessionConfiguration - Foundation | Apple Developer Documentation
So the timeoutInterval
of a NSURLRequest
would override the timeoutIntervalForRequest
of a NSURLSession
but only if it is considered to be "more restrictive" by the system, otherwise the value of NSURLSession
will win.