【发布时间】:2015-07-14 21:01:48
【问题描述】:
这是我的下载代码:
let url = NSURL(string:"http://www.zastavki.com/pictures/originals/2013/Photoshop_Image_of_the_horse_053857_.jpg")!
let documentsDirectoryURL = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first as! NSURL
NSURLSession.sharedSession().downloadTaskWithURL(url, completionHandler: {
(location, response, error) -> Void in
if let error = error {
println(error.description)
}
else {
println("Finished downloading \"\(response.suggestedFilename)\".")
println(location.path!)
println("Started saving \"\(response.suggestedFilename)\".")
if NSFileManager().moveItemAtURL(location, toURL: documentsDirectoryURL.URLByAppendingPathComponent(response.suggestedFilename!), error: nil) {
println("File saved")
} else {
println("The File \(response.suggestedFilename!) was not saved.")
}
}
}).resume()
就像现在一样,响应只能在完成处理程序内部访问。
我的问题是如何在下载完成之前访问响应?
我需要知道 NSURLResponse:
- 预期内容长度
- 建议的文件名
- MIME 类型
【问题讨论】:
标签: ios swift nsurl nsurlsession