Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between NSURLSessionDataTask vs NSURLSessionDownloadTask

In latest apple introduce new NSURLSession in replace of NSURLConnection, so in there are different task , so what is the difference between NSURLSessionDataTask, NSURLSessionDownloadTask ?

and in which scenario use NSURLSessionTask and where NSURLSessionDownloadTask?

like image 572
Toseef Khilji Avatar asked Dec 16 '13 06:12

Toseef Khilji


1 Answers

NSURLSessionDataTask : Data tasks exchange data using NSData. NSURLSessionDataTask is not supported in Background Sessions.

Data tasks send and receive data using NSData objects. Data tasks are intended for short, often interactive requests from your app to a server. Data tasks can return data to your app one piece at a time after each piece of data is received, or all at once through a completion handler. Because data tasks do not store the data to a file, they are not supported in background sessions.

NSURLSessionDownloadTask : NSURLSessionDownloadTask directly writes the response data to a temporary file. It supports background downloads when the app is not running.

Download tasks retrieve data in the form of a file, and support background downloads while the app is not running.

I guess below image give you better knowledge:

enter image description here

like image 82
Toseef Khilji Avatar answered Sep 24 '22 21:09

Toseef Khilji