Search code examples
iosnsurlsessionnsurlsessiondownloadtasknsurlsessiondatatask

When to use NSURLSessionDownloadTask and NSURLSessionDataTask?


What is the difference between these 2. I am able to get the data from the server using both.


Solution

  • There are three types of concrete session tasks in this context:

    NSURLSessionDataTask: Use this task for HTTP GET requests to retrieve data from servers to memory.

    NSURLSessionUploadTask: Use this task to upload a file from disk to a web service, typically via a HTTP POST or PUT method.

    NSURLSessionDownloadTask: Use this task to download a file from a remote service to a temporary file location.

    You can also suspend, resume and cancel tasks. NSURLSessionDownloadTask has the additional ability to pause for future resumption.enter image description here