Skip to content

ixuea/CocoaDownloader

Repository files navigation

CocoaDownloader

English | 中文

An powerful download library for iOS, macOS. Report an issue, Android use AndroidDownloader.

iOS Demo

See iOSDemo for details.

macOS Demo

See macOSDemo for details.

Getting Started

1.Import header file

#import <CocoaDownloader/CocoaDownloader.h>

2.Create a DownloadManager instance

self.downloadManager=[DownloadManager sharedInstance];

Or detailed configuration.

//Custom config
DownloadConfig *config=[[DownloadConfig alloc] init];

//Download task number
config.downloadTaskNumber=2;

self.downloadManager=[DownloadManager sharedInstance:config];

3.Download a file

//save path
NSString *documentPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *path=[documentPath stringByAppendingPathComponent:@"IxueaCocoaDownloader/a.apk"];

NSLog(@"ixuea download save path:%@",path);

//Create download info.
self.downloadInfo=[[DownloadInfo alloc] init];

//Set download save path.
[self.downloadInfo setPath:path];

//Set download url.
[self.downloadInfo setUri:DEFAULT_URL];

//Set download info id.
[self.downloadInfo setId:DEFAULT_ID];

NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0];

NSTimeInterval currentTimeMillis=[date timeIntervalSince1970];

//Set download create time.
[self.downloadInfo setCreatedAt:currentTimeMillis];

//Set download callcabk.
[self.downloadInfo setDownloadBlock:^(DownloadInfo * _Nonnull downloadInfo) {
    //TODO Progress, status changes are callbacks.
}];

//Start download.
[self.downloadManager download:self.downloadInfo];

See SampleController for details.

More

See the example code, iOS and macOS platform downloaders use the same API.

Author

Smile - @ixueadev on GitHub, Email is [email protected], See more ixuea(http://www.ixuea.com)

iOS & macOS QQ development group: 965841894.