upload(urlRequest.1, with: urlRequest.0)
Progress {(bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in // Error Comes Here
print("\(Int64(totalBytesWritten)) / \(Int64(totalBytesExpectedToWrite))")
}
.responseJSON
{
response in
hideLoading()
showToast("Profile Updated Successfully!!")
}
答案 0 :(得分:1)
问题是您已将.uploadProgress
替换为Progress
,但未将闭包的三个参数更改为单个Progress
参数。
当您致电.uploadProgress
时,该闭包的第一个参数是Progress
(以前称为NSProgress
)。但是Alamofire方法名称uploadProgress
没有变化。只有关闭的参数已经改变。
因此你需要像:
Alamofire.upload(data, with: request)
.uploadProgress { progress in
print(progress.fractionCompleted)
}
.responseJSON { response in
self.hideLoading()
switch response.result {
case .failure(let error):
self.showToast("Problem uploading: \(error.localizedDescription)")
case .success:
self.showToast("Profile Updated Successfully!!")
}
}
从底线开始,上传进度方法称为uploadProgress
,它需要一个参数NSProgress
/ Progress
对象。