Answer the question
In order to leave comments, you need to log in
Swift/Objective-C. How to convert NSData to zip and then unpack to project folder?
let url: NSURL = NSURL(string: "http://.../data.zip")!
let sharedSession = NSURLSession.sharedSession()
let downloadTask:NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(url, completionHandler: { (location: <#NSURL!#>, response: <#NSURLResponse!#>, error:<#NSError!#>) -> Void in nil
let dataObject = NSData(contentsOfURL: location)
// ???
})
downloadTask.resume()
Answer the question
In order to leave comments, you need to log in
SSZipArchive
library , you need to import libz.dylib in addition to the library itself
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")!)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question