Ios 跟踪Alamofire请求的进度
我想知道是否有可能根据请求显示进度。我将图像转换为base64字符串,并使用参数将其发送到服务器。有没有办法追踪它的进展?我想尝试类似的方法。但是我不能在我的Alamofire.request中添加进度部分。有什么我遗漏的吗Ios 跟踪Alamofire请求的进度,ios,swift,alamofire,Ios,Swift,Alamofire,我想知道是否有可能根据请求显示进度。我将图像转换为base64字符串,并使用参数将其发送到服务器。有没有办法追踪它的进展?我想尝试类似的方法。但是我不能在我的Alamofire.request中添加进度部分。有什么我遗漏的吗 Alamofire.request(.POST, URL, parameters: parameter, encoding: .JSON) .progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
Alamofire.request(.POST, URL, parameters: parameter, encoding: .JSON)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
// track progress here
}
.responseJSON { response in
// Do your stuff
}
不确定,但我认为当前版本的Alamofire使用的是
下载进度
,而不是进度
:
Alamofire.request(/*…*/).downloadProgress{progress in
progress.fractionCompleted//值介于0和1之间
}
.responseJSON{/*…*/}
您可以这样做
Alamofire.upload(multipartFormData: { (multipartFormData) in
}, with: URL, encodingCompletion: { (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (Progress) in
// Here you get the progress
print(Progress.fractionCompleted)
})
upload.responseJSON { response in
case .failure( _ ):
}
})
看起来很相似:是的,但我知道我的数据的大致大小,我想显示进度。编辑你的问题,提供更多关于你的问题和你想要实现的目标的详细信息。正如所建议的,这看起来像是重复的。你的意思是要更新UI吗?不,我正在尝试在我的Alamofire.request中添加进度部分。我想我错过了什么。顺便说一句,我刚刚更新了我的问题@SoroushI尝试了此操作,但下载进度分数始终为0,totalUnitCount为-1。这个怎么了?