我想使用 AFNetworking 快速从 URL 下载文件,并显示下载进度。我有这段代码,但它不起作用:
func downloadPdf()
{
var request = NSURLRequest(URL: NSURL(string: "http://www.sa.is/media/1039/example.pdf"))
let session = AFHTTPSessionManager()
var progress: NSProgress?
var downloadTask = session.downloadTaskWithRequest(request, progress: &progress, destination: {(file, responce) in self.pathUrl},
completionHandler:
{
response, localfile, error in
println("response \(response)")
})
downloadTask.resume()
}
var pathUrl: NSURL
{
var path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
var url = NSURL(string: path.stringByAppendingPathComponent("file.pdf"))
println(url.path)
return url
}
我做错了什么?