Swift
- 4 ответа
- 0 вопросов
3
Вклад в тег
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")!)