Available in iOS 7.0 and later
NSURLSessionUploadTask class is a subclass of
NSURLSessionDataTask, which in turn is a concrete subclass of
NSURLSessionTask. The methods associated with the
NSURLSessionUploadTask class are documented in NSURLSessionTask Class Reference.
Upload tasks are used for making HTTP requests that require a request body (such as
PUT). They behave similarly to data tasks, but you create them by calling different methods on the session that are designed to make it easier to provide the content to upload. As with data tasks, if the server provides a response, upload tasks return that response as one or more
NSData objects in memory.
When you create an upload task, you provide an
NSMutableURLRequest object that contains any additional headers that you might need to send alongside the upload, such as the content type, content disposition, and so on.
While the upload is in progress, the task calls the session delegate’s
URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend: method periodically to provide you with status information.
When the upload phase of the request finishes, the task behaves like a data task, calling methods on the session delegate to provide you with the server’s response—headers, status code, content data, and so on.