I have created a download handler which uses the downloadProgress and response completion handlers, but I want to convert this to Swift 5.5's new async/await syntax since AlamoFire released a version which supports swift concurrency.
Here's my current code using completion handlers
func startDownload() {
let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
AF.download("https://speed.hetzner.de/1GB.bin", to: destination)
.downloadProgress { progress in
print(progress.fractionCompleted)
}
.response { response in
print(response)
}
}
Here's my attempt to convert to async/await syntax, but I am not sure how to implement downloadProgress
func startDownload() async {
let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
let downloadTask = AF.download("https://speed.hetzner.de/1GB.bin", to: destination).serializingDownloadedFileURL()
do {
let fileUrl = try await downloadTask.value
print(fileUrl)
} catch {
print("Download error! \(error.localizedDescription)")
}
}
I would appreciate any help.