如何在iOS应用中显示Web服务调用的进度栏

时间:2019-03-19 12:04:22

标签: ios objective-c ios7 progress-bar

我想在ios应用中显示一个Web API调用的进度条,而不是仅向用户显示活动指示器,直到完成Web服务,向他显示进度状态对用户友好。看到了许多示例,这些示例显示了带有用户定义时间的进度条,但这些示例与WEB API调用持续时间无关。那么有人可以指导我完成上述任务吗?

1 个答案:

答案 0 :(得分: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..