0

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 ?

Mike Hay
  • 2,828
  • 21
  • 26
SURESH SANKE
  • 1,653
  • 17
  • 34
  • 2
    If your web API call is an upload or a download, then you would be able to get progress indication using a **URLSessionUploadTask** or **URLSessionDownloadTask** and implementing their delegate methods. Otherwise, web API calls are expected to complete really quickly, and there isn't really a way to do accurate progress indication. – Mike Hay Mar 19 '19 at 12:59
  • 1
    Possible duplicate of [get progress from dataTaskWithURL in swift](https://stackoverflow.com/questions/30543806/get-progress-from-datataskwithurl-in-swift) – El Tomato Mar 19 '19 at 13:02

1 Answers1

2
    // 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..
Sukh
  • 1,278
  • 11
  • 19
  • 1
    The question is tagged Objective-C, not Swift. Please post questions in the correct language. – rmaddy Mar 19 '19 at 13:51