I'm a freshman in Swift and working on an app which would resume download after being closed. I found some similar questions from Stack overflow but they are not very helpful to my work.
let dataTask = self.session.downloadTaskWithURL(self.bigFile!)
dataTask.resume()
I'm trying to resume download by this way, but it didn't work. I also want to ask how to update the progressView after the download is stopped and resumed
func URLSession(session: NSURLSession, task: NSURLSessionTask,
didCompleteWithError sessionError: NSError?) {
if let error = sessionError {
print("error : \(error)")
if let resumedData = error.userInfo[NSURLSessionDownloadTaskResumeData]
as? NSData {
let resumeData = session.downloadTaskWithResumeData(resumedData)
resumeData.resume()
}
}
}
func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
let progress = Float(totalBytesWritten)/Float(totalBytesExpectedToWrite)
self.progressView.progress = progress
}
And do I need to generate a local path instead of the temporary one for storing the downloaded data (I don't need to publish the app, just show to my tutor.) ? Thanks in advance