AHDownloadTool 0.1.12

AHDownloadTool 0.1.12

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

Andy Tong 维护。



  • 作者:
  • ivsall2012

AHDownloadTool

使用说明

1. 下载

AHDataTaskManager.donwload(fileName: "testURL4.mp3", url: testURL4, fileSizeCallback: { (fileSize) in
/// store the file size if needed
}, progressCallback: { (progress) in
/// the progress will only be updated when the percent whole number changes,
/// e.g. from %33 to %34, not for those from %33.33 to %33.99.
/// Otherwise the main thread is going to be filled up with those progress updates.
}, successCallback: { (filePath) in
print("testURL4 ok, path:\(filePath)")
}) { (error) in
print("testURL4 failed error:\(String(describing: error))")
}

路径和文件名

默认的临时和缓存目录是 NSTemporaryDirectory() 和 NSSearchPathForDirectoriesInDomains。
默认的文件名是下载 URL 的最后一个路径组件。

您可以使用另一个重载的下载方法指定这三个属性,(这里太长了无法展示,Xcode 的自动完成可以告诉您哪个方法)

下载控制和状态

A. AHDataTaskManager 提供了下载控制,例如 pauseAll(),resumeAll() 或 pause(url: String) 以特定任务根据其 URL 字符串进行暂停。

B. AHDataTaskManager 提供的其他 API

public static func getCurrentTaskURLs() -> [String]
public static func getState(_ urlStr: String) -> AHDataTaskState
public static func getTaskTempFilePath(_ urlStr: String) -> String?
public static func getTaskCacheFilePath(_ urlStr: String) -> String?

2. 文件大小探测。支持下载 URL 重新定向。

A: 探测单个 URL

AHFileSizeProbe.probe(urlStr: testURL4) { (size) in
print("single size:\(size)")
}

B: 探测一组 URL

let fileUrls = [testURL1,testURL2,testURL3,testURL4]
AHFileSizeProbe.probeBatch(urlStrs: [testURL1,testURL2,testURL3,testURL4]) { (sizeDict) in
/// NOTE: the sizeDict is a map from the ORIGINAL download url you passed in, to its file size.
for (offset: i, element: (key: url, value: fileSize)) in sizeDict.enumerated() {
print("url:\(value) fileSize:\(fileSize)")
}
}

示例

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

要求

安装

AHDownloadTool 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile:

pod "AHDownloadTool"

作者

Andy Tong,[email protected]

许可证

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