Cedric
我是谁?
嘿,我叫 Cedric,我出生于帮助 iOS / macOS 开发者解决一个相当困难的任务,那就是下载文件。
我的职责是什么?
除了下载文件外,我还能执行如下操作
- 通过 MulticastDelegate 通知更新
- 以 串行 或 并行(带有限制) 选项执行操作
- 像浏览器一样下载,始终创建新文件
- 重用 同一资源的已下载文件
- 通知队列中的所有资源都已下载
- 将资源中指定的属性应用于文件
示例使用
let resource = DownloadResource(id: asset.id, source: asset.url, destinationName: asset.name + ".mp3", mode: .notDownloadIfExists)
try cedric.enqueueDownload(forResource: resource)
func cedric(_ cedric: Cedric, didFinishDownloadingResource resource: DownloadResource, toFile file: DownloadedFile) {
do {
let url = try file.url()
guard let image = UIImage(contentsOfFile: url.path) else { return }
fileImageView.image = image
} catch let error {
...
}
}
Cedric 配置模式
如我之前所述,我可以以不同模式工作,支持串行或并行下载。
使用串行模式(按队列一个接一个下载文件)
let configuration = CedricConfiguration(mode: .serial)
return Cedric(configuration: configuration)
使用并行模式(同时执行3个任务)
let configuration = CedricConfiguration(mode: .parallel(max: 3))
return Cedric(configuration: configuration)
重要提示 默认情况下,所有文件都存储在“下载”目录中。如果您想将它们存储在不同的目录中,请将目录名称传递给CedricConfiguration
对象。在使用FileManager.cedricPath(...)
时也应传递相同的配置。
Carthage
在Cartfile中添加以下条目
github "appunite/Cedric"
然后运行carthage update
。
Cocoapods
在Podfile中添加以下条目
pod 'Cedric'
然后运行pod install
。
贡献
项目由Szymon Mrozek创建和维护。
我们欢迎您报告或修复漏洞。我们也想听听您对功能建议的意见。如果您有任何使Cedric变得更好的想法,欢迎您发送Pull Request。
许可协议
Cedric是在MIT许可下发布的。有关更多信息,请参阅License.md。