Библиотека
SSZipArchive, нужно, помимо самой библиотеки, импортировать еще libz.dylib
import Foundation
class DownloadManager: NSObject, NSURLSessionDownloadDelegate {
let backgroundSession: NSURLSession!
override init() {
super.init()
let config = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("YOUR.COM.NAME") // Вообще любой уникальный идентификатор, e.g. com.toster.zip.BackgroundSession
backgroundSession = NSURLSession(configuration: config, delegate: self, delegateQueue: nil)
}
func downloadWithURL(url: NSURL) {
let task = backgroundSession.downloadTaskWithURL(url)
task.resume()
}
func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) {
let destination = NSHomeDirectory().stringByAppendingString("/Desktop/unzip/")
SSZipArchive.unzipFileAtPath(location.path!, toDestination: destination)
}
}
let manager = DownloadManager()
manager.downloadWithURL(NSURL(string: "http://.../data.zip")!)
Распакованный архив будет в /Desktop/unzip/