swift 断点续传下载工具,重启APP恢复临时下载数据
通过 CocoaPods
pod 'XCDownloadTool'
##使用方法
let url:URL = URL(string: "https://......./687474703a2f2f692e696d6775722e636f6d2f30684a384d7a572e676966")!
let cacheDir:String = NSTemporaryDirectory()
let directory = cacheDir.appending("simon")
self.downloadTool = XCDownloadTool(url: url, fileIdentifier: nil, targetDirectory: directory, shouldResume: true)
//是否覆盖旧文件
self.downloadTool?.shouldOverwrite = true
//下载进度
self.downloadTool?.downloadProgress = {[weak self] (progress)-> Void in
self?.progressLabel.text = "progress: \(progress)"
}
//下载完成
self.downloadTool?.downLoadCompletion = {[weak self] (finished:Bool ,targetPath:String?, error:Error?) -> Void in
self?.progressLabel.text = "download finished"
if let _ = targetPath{
let image:UIImage? = UIImage.init(contentsOfFile: targetPath!)
self?.imageView.image = image
}
}
//开始或继续下载
self.downloadTool?.startDownload()
//暂停下载
self.downloadTool?.suspendDownload()
The MIT License (MIT). 详情见 License 文件.