URLSessionTask
A task, like downloading a specific resource, performed in a URL session.
Declaration
class URLSessionTaskMentioned in
Overview
The URLSessionTask class is the base class for tasks in a URL session. Tasks are always part of a session; you create a task by calling one of the task creation methods on a URLSession instance. The method you call determines the type of task.
Use URLSession‘s dataTask(with:) and related methods to create URLSessionDataTask instances. Data tasks request a resource, returning the server’s response as one or more
NSDataobjects in memory. They are supported in default, ephemeral, and shared sessions, but are not supported in background sessions.Use URLSession‘s uploadTask(with:from:) and related methods to create URLSessionUploadTask instances. Upload tasks are like data tasks, except that they make it easier to provide a request body so you can upload data before retrieving the server’s response. Additionally, upload tasks are supported in background sessions.
Use URLSession’s downloadTask(with:) and related methods to create URLSessionDownloadTask instances. Download tasks download a resource directly to a file on disk. Download tasks are supported in any type of session.
Use URLSession’s streamTask(withHostName:port:) or streamTask(with:) to create URLSessionStreamTask instances. Stream tasks establish a TCP/IP connection from a host name and port or a net service object.
After you create a task, you start it by calling its resume() method. The session then maintains a strong reference to the task until the request finishes or fails; you don’t need to maintain a reference to the task unless it’s useful for your app’s internal bookkeeping.
Topics
Controlling the task state
Obtaining task progress
progresscountOfBytesExpectedToReceivecountOfBytesReceivedcountOfBytesExpectedToSendcountOfBytesSentNSURLSessionTransferSizeUnknown
Obtaining general task information
Determining task behavior
Using a task-specific delegate
Scheduling tasks
countOfBytesClientExpectsToReceivecountOfBytesClientExpectsToSendNSURLSessionTransferSizeUnknownearliestBeginDate