URLSessionDataTask
A URL session task that returns downloaded data directly to the app in memory.
Declaration
class URLSessionDataTaskMentioned in
Overview
A URLSessionDataTask is a concrete subclass of URLSessionTask. The methods in the URLSessionDataTask class are documented in URLSessionTask.
A data task returns data directly to the app (in memory) as one or more NSData objects. When you use a data task:
During upload of the body data (if your app provides any), the session periodically calls its delegate’s urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:) method with status information.
After receiving an initial response, the session calls its delegate’s urlSession(_:dataTask:didReceive:completionHandler:) method to let you examine the status code and headers, and optionally convert the data task into a download task.
During the transfer, the session calls its delegate’s urlSession(_:dataTask:didReceive:) method to provide your app with the content as it arrives.
Upon completion, the session calls its delegate’s urlSession(_:dataTask:willCacheResponse:completionHandler:) method to let you determine whether the response should be cached.
For examples of using data tasks for fetching and uploading data, see Fetching website data into memory and Uploading data to a website.