Reputation: 1253
I trying to download a pdf file from url with progress. All it's ok. But i can't found setCompletionBlock, why? This is my working code:
println("progress: \(0.0)")
let request: NSURLRequest = NSURLRequest(URL: NSURL(string: document.link)!)
let operation: AFURLConnectionOperation = AFHTTPRequestOperation(request: request)
let paths: NSArray = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let filePath: NSString = paths.objectAtIndex(0).stringByAppendingPathComponent("pdf_\(document.id).pdf")
operation.outputStream = NSOutputStream(toFileAtPath: filePath, append: false)
operation.setDownloadProgressBlock({(bytesRead, totalBytesRead, totalBytesExpectedToRead) -> Void in
var total: CGFloat = CGFloat(totalBytesRead) / CGFloat(totalBytesExpectedToRead)
println("progress: \(total)")
})
//operation.setCompletionBlock ... can't found this block?!
operation.start()
Upvotes: 2
Views: 475
Reputation: 437432
You are casting your AFHTTPRequestOperation
to a AFURLConnectionOperation
:
let operation: AFURLConnectionOperation = AFHTTPRequestOperation(request: request)
But setCompletionBlockWithSuccess
is defined in AFHTTPRequestOperation
, not AFURLConnectionOperation
.
Instead, just let operation
be a AFHTTPRequestOperation
:
let operation = AFHTTPRequestOperation(request: request)
Then it will recognize setCompletionBlockWithSuccess
successfully.
Upvotes: 3