Latest 0.1.12
Homepage https://github.com/ivsall2012/AHDownloadTool
License MIT
Platforms ios 8.0
Authors

Usage

1. Download

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))")
}

Paths and file name

The default temporary and cache direatory is NSTemporaryDirectory() and cachesDirectory from NSSearchPathForDirectoriesInDomains.
The default filename is the last path component of thr download url.

You can always specify those three attributes, by using another overloaded download method(It’s too long to put it on here, Xcode’s autocomplete will tell you which one).

Download controls and States

A. AHDataTaskManager provides download controls, such as pauseAll(), resumeAll(), or pause(url: String) for specific task based on its url string.

B. Other APIs provided by AHDataTaskManager:

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. File size probe. Support download url redirections.

A: Probe a single url

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

B: Probe a batch of urls

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

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

AHDownloadTool is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "AHDownloadTool"

Author

Andy Tong, [email protected]

License

AHDownloadTool is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "AHDownloadTool",
    "version": "0.1.12",
    "summary": "A short description of AHDownloadTool.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/ivsall2012/AHDownloadTool",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "ivsall2012": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ivsall2012/AHDownloadTool.git",
        "tag": "0.1.12"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "AHDownloadTool/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This