测试已测试 | ✗ |
语言语言 | Swift Swift |
许可 | MIT |
发布最后发布 | 2017年3月 |
Swift Swift 版本 | 3.0 |
SPM 支持 SPM | ✗ |
由 Simon 维护。
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()
MIT 许可证 (MIT)。详情见 License 文件。