Vinoth kanna
Vinoth kanna

Reputation: 57

IOS: Which is the best way to download a Large size file from server

I have a zip file which contains db. i need to download that zip file when the user open the app at first time.So am using

NSData *urlData =[NSData dataWithContentsOfURL:urlToRequest];

to download a file in GCD mode. Since it's working fine,am not getting any errors.

But, is it ok to download a large File using the above method or we have to use NSURLConnection for large file download. Please advice.

Upvotes: 3

Views: 4486

Answers (1)

gunjot singh
gunjot singh

Reputation: 2598

You should use NSURLSession => NSURLSessionDownloadTask api

What is wrong with below for large file download

[NSData dataWithContentsOfURL:urlToRequest];
  • Since, you are having large file to download which take huge time, thus more chances of connection break or any other interruption, which won't be resumed from last downloaded progress
  • In case of a Large file, user should be provide an ability to pause and resume, above won't support that.
  • Background downloading is also not supported
  • Progress Status is not supported, which is very important for users, so as to keep them waiting on your app.

Now, NSURLSession => NSURLSessionDownloadTask supports all of the above.

Follow this nice tutorial:

NSURLSession Tutorial:

Upvotes: 5

Related Questions