URLSession - 下载远程目录

URLSession - Download remote directory

我目前正在使用基于此教程 http://sweettutos.com/2015/11/06/networking-in-swift-how-to-download-a-file-with-nsurlsession/ 的代码来使用 URLSession.downloadTask 下载远程文件。这非常简单。但是我现在想下载远程目录的全部内容。 我可以使用 URLSessionDownloadTask 还是仅适用于单个文件?如果没有,那么如何获取远程目录中包含的文件列表,以便我可以对每个文件单独使用 downloadTask?

首先你想错了

remote服务器,只有一个file可以是downloaded(不是文件夹)和save里面的app。您必须下载的文件 extension 应该是来自服务器端的 configure。然后client这边可以使用Sweettutos教程。

First thing you have to do was :

Talk with the server side developer that he had to zip the remote directory in (.zip or .rar) that you can download it only.

然后,在你的代码处下载服务器端给你的url并保存在文档目录下,解压并读取你想要的文件。

At the URLSession Documentation :

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

所以,没有办法你可以下载远程目录(未知文件扩展名),直到你让某些人可以使用该远程文件服务器端的文件扩展名。