现在我显示进度条,硬编码为 2 秒(平均响应时间)。但我希望它是智能的。
我的请求是这样的。
func makeRequest(to endPoint: String) {
Alamofire.request(endPoint).responseJSON{ response in
if let value = response.result.value {
let responseInJSON = JSON(value)
self._responseInJSON = responseInJSON
}
}
}
期待您的帮助。 谢谢。
最佳答案
我希望它能帮助我在评论中注明。
func makeRequest(to endPoint: String) {
// here you can showActivetyIndicator start progressing here
Alamofire.request(endPoint).responseJSON{ response in
if let value = response.result.value {
let responseInJSON = JSON(value)
self._responseInJSON = responseInJSON
}
// here you can hide Your ActivetyIndicator here
}
}
简单地说,您可以在 Alamofire
请求开始之前开始进度,然后在获得 API 响应后停止。不需要像 2 秒这样的静态时间。
关于ios - 有没有办法在 Alamofire api 请求的响应等待期间显示事件指示器或进度条?使用 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41039853/