alamofire如何获取部分下载的数据?

时间:2017-09-06 17:21:59

标签: swift3 alamofire

我想显示部分下载数据。在downloadProgress回调中,我可以访问Progress实例,其中包含字节或百分数的进度。但是我如何访问部分下载的数据?

1 个答案:

答案 0 :(得分:0)

我在Alamofire的消息来源中找到了它:

// MARK: Stream
/// Sets a closure to be called periodically during the lifecycle of the request as data is read from the server.
///
/// This closure returns the bytes most recently received from the server, not including data from previous calls.
/// If this closure is set, data will only be available within this closure, and will not be saved elsewhere. It is
/// also important to note that the server data in any `Response` object will be `nil`.
///
/// - parameter closure: The code to be executed periodically during the lifecycle of the request.
///
/// - returns: The request.
@discardableResult
open func stream(closure: ((Data) -> Void)? = nil) -> Self {
    dataDelegate.dataStream = closure
    return self
}