我有一個應用程序,我需要從互聯網上下載文件時,我下載文件它的工作很好,但我的問題是當我按下暫停按鈕暫停下載一分鐘或更長時間我從簡歷獲得零數據從URLSessionDownloadTask恢復數據始終沒有
下面我的代碼:
@IBAction func startDownloading(_ sender: UIButton)
{
isDownload = true
sessionConfig = URLSessionConfiguration.default
let operationQueue = OperationQueue.main
session = URLSession.init(configuration: sessionConfig, delegate: self, delegateQueue: operationQueue)
let url = URL(string: "www.example.com")
downloadTask = session.downloadTask(with: url!)
downloadTask.resume()
}
@IBAction func pause(_ sender: UIButton)
{
if downloadTask != nil && isDownload
{
self.downloadTask!.cancel(byProducingResumeData: { (resumeData) in
// here is the nil from the resume data
})
isDownload = false
downloadTask = nil
pasueBtnOutlet.setTitle("Resume", for: .normal)
}
if !isDownload && downloadData != nil
{
downloadTask = session.downloadTask(withResumeData: downloadData as Data)
downloadTask.resume()
isDownload = true
downloadData = nil
pasueBtnOutlet.setTitle("Pause", for: .normal)
}
}
請幫我
感謝所有
可能的複製(https://stackoverflow.com/questions/24215610/nsurlsessiondownloadtask-cancelbyproducingresumedata-返回null) –
這是dublicate的https://stackoverflow.com/questions/24215610/nsurlsessiondownloadtask-cancelbyproducingresumedata-return-null –