XCFetch工具 0.1.1

XCFetch工具 0.1.1

测试已测试
语言语言 Swift Swift
许可 MIT
发布最后发布2017年3月
Swift Swift 版本3.0
SPM 支持 SPM

Simon 维护。



  • Simon

XCDownloadTool for Swift

English

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 文件