swift3 iOS断点续传下载工具

XCDownloadTool for iOS swift3


iOS swift 断点续传下载工具,重启APP恢复临时下载数据


通过 CocoaPods  安装

pod'XCDownloadTool'



使用方法

let url:URL = URL(string: "https://......./...")!

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()


项目地址  https://github.com/wuchun4/XCDownloadTool

你可能感兴趣的:(swift3 iOS断点续传下载工具)