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

Posted

技术标签:

【中文标题】alamofire 如何获取部分下载的数据?【英文标题】:alamofire how to obtain partially downloaded data? 【发布时间】:2017-09-06 17:21:59 【问题描述】:

我想显示部分下载数据。在downloadProgress 回调中,我可以访问进度实例,并以字节或百分比为单位。但是如何访问部分下载的数据?

【问题讨论】:

【参考方案1】:

我在 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

【讨论】:

以上是关于alamofire 如何获取部分下载的数据?的主要内容,如果未能解决你的问题,请参考以下文章

如何暂停应用程序直到使用 Alamofire 下载 json 数据?

如何使用 Alamofire swift 3 从这个 JSON 中获取值

如何在 Alamofire 4 中进行多部分表单数据上传?

从 URL 下载 UITableIViewCell 图像

Swift 2 - 如何从 Alamofire.responseJSON 获取数据

如何使用 Alamofire,Swift 4 为 UICollectionView 获取 JSON 数据