Reputation: 1663
I would like to show a progress bar for one of the web API call in ios app.Instead of showing only activity indicator to the user untill the web service is completed, showing him the status of progress is user friendly.I have seen many examples showing the progress bar with the user defined time but those are not related to WEB api call time duration. So can anyone guide me to do the above task ?
Upvotes: 0
Views: 828
Reputation: 1398
// like iam using SVProgress for uplaod an image
// for showing Progress iam getting Progress.fractionCompleted from uploadProgress
eg:-
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(data!, withName: "media", fileName: "media.jpeg", mimeType: "media/jpeg")
for (key, value) in parameters! {
multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
}
}, to:baseUrl,headers:parameters)
{ (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (Progress) in
print("Upload Progress: \(Progress.fractionCompleted)")
SVProgressHUD.showProgress(Float(Progress.fractionCompleted))
})
upload.responseJSON { response in
//self.delegate?.showSuccessAlert()
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
// self.showSuccesAlert()
//self.removeImage("frame", fileExtension: "txt")
SVProgressHUD.dismiss()
// Hope its works for you..
Upvotes: 2