简体   繁体   English

iOS:这是从服务器下载大文件的最佳方法

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

I have a zip file which contains db. 我有一个包含db的zip文件 i need to download that zip file when the user open the app at first time.So am using 用户第一次打开应用程序时,我需要下载该zip文件。

NSData *urlData =[NSData dataWithContentsOfURL:urlToRequest];

to download a file in GCD mode. 以GCD模式下载文件。 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. 但是,可以使用上述方法下载大型文件NSURLConnection还是必须使用NSURLConnection进行大型文件下载。 Please advice. 请指教。

You should use NSURLSession => NSURLSessionDownloadTask api 您应该使用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. 现在,NSURLSession => NSURLSessionDownloadTask支持上述所有功能。

Follow this nice tutorial: 遵循这个不错的教程:

NSURLSession Tutorial: NSURLSession教程:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM