Я выбираю файлы из iCloud и загружаю их в AWS S3.Я перечисляю выбранные файлы со статусом загрузки индикатора выполнения в ячейке таблицы.Каждая ячейка имеет отдельный заголовок файла и процесс загрузки, который я поддерживаю.Здесь все почти готово, но если я загружаю два файла, то в tableview первая ячейка зависла, а вторая - в процессе загрузки.
Моя функция загрузки
private func upload(file url: URL, keyname : String, exten: String) {
let bucket = S3BucketName
let key = keyname
let contentType = "text/\(exten)"
let expression = AWSS3TransferUtilityUploadExpression()
expression.progressBlock = progressBlock
let task = transferUtility.uploadFile(url,
bucket: bucket,
key: key,
contentType: contentType,
expression: expression,
completionHandler: completionHandler)
task.continueWith { (task) -> Any? in
if let error = task.error {
DispatchQueue.main.async {
//self.infoLabel.text = "Error: \(error.localizedDescription)"
}
return nil
}
if let uploadTask = task.result {
self.uploadTask = uploadTask
DispatchQueue.main.async {
//self.infoLabel.text = "Generating Upload File"
//self.uploadRequests.append(self.uploadTask)
self.tableView_util.reloadData()
}
}
return nil
}
}
Ячейка Tableview
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellutil", for: indexPath) as! UtilityTableViewCell
let item = tableArray[indexPath.row]
cell.name_label_util.text = item.title
cell.control_button_util.tag = indexPath.row
cell.control_button_util.addTarget(self, action: #selector(playpause), for: .touchUpInside)
// MARK - Upload process
progressBlock = { [weak self] task, progress in
guard let strongSelf = self else { return }
DispatchQueue.main.async {
cell.loader_Line_util.progress = Float(progress.fractionCompleted)
//NSLog(@"fraction completed: %f", progress.fractionCompleted);
let percentageUploaded:Float = Float(progress.fractionCompleted) * 100
cell.statusLabel_util.text! = NSString(format:"Uploading: %.0f%%",percentageUploaded) as String
// Need to change
if cell.statusLabel_util.text == "Uploading: 100%" {
cell.statusLabel_util.text = "File Successfully Uploaded!"
cell.loader_Line_util.progress = 1;
self?.tableView_util.reloadData()
}
}
}
completionHandler = { [weak self] task, error in
guard let strongSelf = self else { return }
if let error = error {
DispatchQueue.main.async {
}
return
}