Приветствую,
Возможно ли как то в эту функцию добавить прогресс закачки, чтобы выводилось число
func download(fileURL: URL) -> Bool {
if FileManager().fileExists(atPath: destination.path) {
print("The file already exists at path")
return true
} else {
URLSession.shared.downloadTask(with: fileURL, completionHandler: { (location, response, error)
in
guard
let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,
let mimeType = response?.mimeType, mimeType.hasPrefix("audio"),
let location = location, error == nil
else { return }
do {
try FileManager.default.moveItem(at: location, to: self.destination)
print("file saved")
} catch {
print(error)
}
}).resume()
return false }
}
Я понимаю что нужно что-то типо такого, только куда мне это приткнуть
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask,
didWriteData bytesWritten: Int64, totalBytesWritten: Int64,
totalBytesExpectedToWrite: Int64) {
// 1
guard let url = downloadTask.originalRequest?.url,
let download = downloadService.activeDownloads[url] else { return }
// 2
download.progress = Float(totalBytesWritten) / Float(totalBytesExpectedToWrite)
Спасибо и извиняюсь сразу за глупый вопрос