Skip to content

imjoych/JCDownloader

Repository files navigation

JCDownloader

A useful iOS downloader framework based on AFNetworking.

Features

This framework supports the development of iOS 7.0+ in ARC.

  • Single file download start/pause/remove operation and so on.
  • File list downloads with groupId.
  • Breakpoint downloading supported.

Single file download

JCDownloadItem *downloadItem = [[JCDownloadItem alloc] init];
downloadItem.downloadUrl = @"download url";
downloadItem.downloadFilePath = @"download file path";
self.operation = [JCDownloadOperation operationWithItem:downloadItem];
[self.operation startWithProgressBlock:^(NSProgress *progress) {
    //update progress
} completionBlock:^(NSURL *filePath, NSError *error) {
    //download operation completion, do something
}];
[self.operation resetProgressBlock:^(NSProgress *progress) {
    //update progress
} completionBlock:^(NSURL *filePath, NSError *error) {
    //download operation completion, do something
}];
[self.operation pauseDownload];
[self.operation removeDownload];

File list downloads

extern NSString *const JCTImageDownloadGroupId;
NSMutableArray *downloadList = [NSMutableArray array];
for (NSInteger index = 0; index < [self urlList].count; index++) {
    JCTImageDownloadItem *item = [[JCTImageDownloadItem alloc] init];
    item.groupId = JCTImageDownloadGroupId;
    item.downloadUrl = [self urlList][index];
    item.downloadFilePath = [JCDownloadUtilities filePathWithFileName:[item.downloadUrl lastPathComponent] folderName:@"downloadImages"];
    JCDownloadOperation *operation = [JCDownloadOperation operationWithItem:item];
    [downloadList addObject:operation];
}
[[JCDownloadQueue sharedQueue] startDownloadList:downloadList];
[[JCDownloadQueue sharedQueue] startDownloadsWithGroupId:JCTImageDownloadGroupId];
[[JCDownloadQueue sharedQueue] pauseDownloadsWithGroupId:JCTImageDownloadGroupId];
[[JCDownloadQueue sharedQueue] removeDownloadsWithGroupId:JCTImageDownloadGroupId];

Downloads notifications

FOUNDATION_EXPORT NSString *const JCDownloadIdKey; ///< download identifier key in notifications userInfo, instance type of the value is NSString.
FOUNDATION_EXPORT NSString *const JCDownloadProgressNotification; ///< notification of download progress.
FOUNDATION_EXPORT NSString *const JCDownloadProgressKey; ///< download progress key in JCDownloadProgressNotification userInfo, instance type of the value is NSProgress.
FOUNDATION_EXPORT NSString *const JCDownloadCompletionNotification; ///< notification of download completion.
FOUNDATION_EXPORT NSString *const JCDownloadCompletionFilePathKey; ///< download completion file path key in JCDownloadCompletionNotification userInfo, instance type of the value is NSURL.
FOUNDATION_EXPORT NSString *const JCDownloadCompletionErrorKey; ///< download completion error key in JCDownloadCompletionNotification userInfo, instance type of the value is NSError.

CocoaPods

To integrate JCDownloader into your iOS project, specify it in your Podfile:

pod 'JCDownloader'

##Contacts If you have any questions or suggestions about the framework, please E-mail to contact me.

Author: Joych E-mail: imjoych@gmail.com

License

JCDownloader is released under the MIT License.