SRDownloadManager 1.2.0

SRDownloadManager 1.2.0

guowilling 维护。



  • 作者:
  • guowilling

SRDownloadManager

基于 NSURLSession 的强大且易于使用的文件下载管理器。提供下载状态、进度和完成回调块。

image

特性

  • 支持断点下载,即使退出应用也能进行多任务下载。
  • 支持自定义文件保存目录或指定文件保存路径。
  • 支持设置最大并发下载量,并设置为等待下载队列模式。
  • 支持按 URL 或名称删除文件,并清除所有已下载的文件。

安装

CocoaPods

pod 'SRDownloadManager' 添加到 Podfile 中,然后在终端中运行 pod install

手动

SRDownloadManager 文件夹拖拽到项目中。

API

+ (instancetype)sharedManager;

/**
 Starts a file download action with URL, download state, download progress and download completion block.
 
 @param URL        The URL of the file which to be downloaded.
 @param destPath   The path to save the file after the download is completed, if pass nil file will be saved in default path.
 @param state      A block object to be executed when the download state changed.
 @param progress   A block object to be executed when the download progress changed.
 @param completion A block object to be executed when the download completion.
 */
- (void)downloadURL:(NSURL *)URL
           destPath:(NSString *)destPath
              state:(void (^)(SRDownloadState state))state
           progress:(void (^)(NSInteger receivedSize, NSInteger expectedSize, CGFloat progress))progress
         completion:(void (^)(BOOL success, NSString *filePath, NSError *error))completion;

使用

[[SRDownloadManager sharedManager] downloadURL:URL destPath:nil state:^(SRDownloadState state) {
    // Called when the download state changed.
} progress:^(NSInteger receivedSize, NSInteger expectedSize, CGFloat progress) {
    // Called when the download progress changed.
} completion:^(BOOL success, NSString *filePath, NSError *error) {
    // Called when the download completion.
}];

自定义

/**
 The directory where the downloaded files are saved, default is .../Library/Caches/SRDownloadManager if not setted.
 */
@property (nonatomic, copy) NSString *saveFilesDirectory;

/**
 The count of max concurrent downloads, default is -1 which means no limit.
 */
@property (nonatomic, assign) NSInteger maxConcurrentCount;

/**
 The mode of waiting for download queue, default is FIFO.
 */
@property (nonatomic, assign) SRWaitingQueueMode waitingQueueMode;

联系信息

如有任何问题,请提交问题或通过电子邮件与我联系。 [email protected]