Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

ios - How to show the blue tick when a image is successfully uploaded to server, and a loading clock for those which are uploading

Hello I am developing an application, where I am uploading multiple images to server and loading on table. What I need to do is I need to show a blue tick mark to images which are successfully loaded to the server and a loader to those which are uploading or not uploaded. Below is code

 Alamofire.upload(multipartFormData: { multipartFormData in for imageData in imagesData {
            multipartFormData.append(imageData, withName: "(imageParameterName)[]", fileName: "(Date().timeIntervalSince1970).jpeg", mimeType: "image/jpeg")
        }
        for (key, value) in parameters {
            multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
        }
    }, to: urlString,

        encodingCompletion: { encodingResult in
            switch encodingResult {
            case .success(let upload, _, _):
                upload.responseJSON { response in

                }
            case .failure(let error):
                print(error)
            }

    })

Any suggestion is most welcome for the flow or process.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can Use DispatchGroup()

let syncGroup = DispatchGroup()
 for i in results {
     self.syncGroup.enter()
     **/* For Like Example api call and success in blue tick image update */**
     let image = UIImage(data: i.imageData! as Data)
     self.viewModel.postUploadImage(imgUpload: image!, description: i.descriptionn, location: i.location, allowPublish: i.allow_publish, cropID: i.crop_id, diseasesID: i.disease_id){
        let count = self.syncGroup.debugDescription.components(separatedBy: ",").filter({$0.contains("count")}).first!.components(separatedBy: CharacterSet.decimalDigits.inverted).filter({Int($0) != nil})
            if count.first != "0"{
               self.syncGroup.leave()
               print("Leave")
               // Blue tick image set
            }
        }
    }
 }
self.syncGroup.notify(queue: DispatchQueue.main, execute: {
      print("Finished all requests.")
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...