AHDownloader 0.1.81

AHDownloader 0.1.81

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

Andy Tong 维护。



  • 作者:
  • ivsall2012

此下载器的特点是它的基于多委托的监控机制。
它不使用块(这会导致潜在的保留循环、崩溃以及更高的维护成本)。
多委托监控就像常规委托一样 - 清晰且易于维护。
您只需要将您的委托添加到 AHDownloader。
您的委托将保持弱引用 - 就像使用通知时不需要移除您的委托一样。

用法

基本 API

/// The url string acts like a UUID for the download task.
AHDownloader.download(url: String)

/// Get the downoad state for a specific download task
AHDownloader.getState(urlStr: String)

/// Cancel and delete currently downloading tasks and their temporary files.
AHDownloader.deleteUnfinishedTasks(_ urls: [String], _ completion:(()->Void)? )

监控

/// Your url string is like a ID for the task. And you differentiate each tasks by their url strings.
/// AHDownloader will remove your delete internally if your delegate gets destoryed.
/// Your delegate is kept weakly inside AHDownloader.
AHDownloader.addDelegate(_ delegate: AHDownloaderDelegate)

/// The Delegate Methods
public func downloaderWillStartDownload(url: String)

public func downloaderDidStartDownload(url: String)

public func downloaderDidUpdate(url: String, progress: Double)

public func downloaderDidUpdate(url: String, fileSize: Int)

/// The path used to store downloading data -- a temporary file path which will be removed when the task finished.
public func downloaderDidUpdate(url: String, unfinishedLocalPath: String)

public func downloaderDidFinishDownload(url: String, localFilePath: String)

public func downloaderDidPaused(url: String)

public func downloaderDidPausedAll()

public func downloaderDidResumedAll()

public func downloaderDidResume(url: String)

public func downloaderCancelAll()

public func downloaderDidCancel(url: String)

/// The downloader already handled removing unfinished files for you.
/// This is just a notification. You should delete unfinishedFilePath for your data models.
public func downloaderDeletedUnfinishedTaskFiles(urls: [String])

/// Will use first delegate that returns a non-nil string
public func downloaderForFileName(url: String) -> String?

示例

要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install

要求

安装

AHDownloader 通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行:

pod 'AHDownloader'

作者

Andy Tong,[email protected]

许可证

AHDownloader 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。