gpt4 book ai didi

ios - AFNetworking 缺少 setCompletionBlock ios swift

转载 作者:可可西里 更新时间:2023-11-01 01:06:20 24 4
gpt4 key购买 nike

我正在尝试从 url 下载 pdf 文件并取得进展。一切都好。但是我找不到setCompletionBlock,为什么?这是我的工作代码:

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()

最佳答案

您正在将 AFHTTPRequestOperation 转换为 AFURLConnectionOperation:

let operation: AFURLConnectionOperation = AFHTTPRequestOperation(request: request)

但是 setCompletionBlockWithSuccess 是在 AFHTTPRequestOperation 中定义的,而不是 AFURLConnectionOperation

相反,让 operation 成为一个 AFHTTPRequestOperation:

let operation = AFHTTPRequestOperation(request: request)

然后就会识别setCompletionBlockWithSuccess成功。

关于ios - AFNetworking 缺少 setCompletionBlock ios swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28585342/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com