An NSURLSessionDataTask is a concrete subclass of NSURLSessionTask. The methods in the NSURLSessionDataTask class are documented in NSURLSessionTask Class Reference.
An NSURLSessionDataTask behaves differently from other subclasses in several subtle ways:
- An NSURLSessionDataTask object returns data directly to the app rather than through a file (as a download task would).
During upload of the body data (if your app provides any), the session periodically calls the delegate’s URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend: method with status information. (It also calls this method for upload tasks.) Upon receiving an initial response, the session calls the delegate’s URLSession:dataTask:didReceiveResponse:completionHandler: method to provide your app with the opportunity to convert the transfer into a download task depending on the returned MIME type and other information.
If your app converts the transfer into a download task, the session calls the delegate’s URLSession:dataTask:didBecomeDownloadTask: method to provide your app with the new download task.
During the transfer, the session calls its delegate’s URLSession:dataTask:didReceiveData: method with data objects containing bits of data as it is received. Upon completion, the session calls its delegate’s URLSession:dataTask:willCacheResponse:completionHandler: method to determine whether the response should be cached.
If this delegate method is provided, it must call the provided completion routine; otherwise, your app leaks memory.
If this delegate method is not provided, the default behavior is to use the caching policy specified in the session’s configuration object.
Unlike download tasks, requests made through NSURLSessionDataTask objects cannot be resumed after they are canceled.