首页 > 解决方案 > 跟踪 Alamofire 请求中的进度

问题描述

我想知道是否可以显示请求的进度。我将图像转换为 base64 字符串并使用参数将其发送到我的服务器。有没有办法跟踪它的进度?我想尝试类似的东西。但我无法在我的 Alamofire.request 中添加进度部分。有什么我想念的吗?

Alamofire.request(.POST, URL, parameters: parameter, encoding: .JSON)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
 // track progress here
 }
.responseJSON { response in
// Do your stuff
}

标签: iosswiftalamofire

解决方案


不确定,但我认为当前版本的 Alamofire 使用downloadProgress而不是progress

Alamofire.request(/* ... */).downloadProgress { progress in
  progress.fractionCompleted // value between 0 and 1
}
.responseJSON { /* ... */ }

推荐阅读