UIProgressView progress update very slow within AlamoFire (async) call

↘锁芯ラ 提交于 2019-12-04 15:11:04

There's a MUCH better way to do this in Alamofire. You can use the progress closure to automatically get a callback when a data transfer occurs on your data task. Here's an example from the README monitoring progress for a download request. The same applies for a data request.

let progressView = UIProgressView(progressViewStyle: .Bar)

let params = ["foo": "bar"]
let URLString = "http://httpbin.org/get"

let request = Alamofire.request(.GET, URLString, parameters: params)
request.progress { _, _, _ in
    progressView.setProgress(request.progress.fractionCompleted, animated: true)
}
request.responseJSON { request, response, json, error in
    println(request)
    println(response)
    println(json)
    println(error)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!