Downloader makes it easy to implement file download functionality.
Switch branches/tags
Pull request Compare This branch is 6 commits ahead of dev2dev:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


URLDownloader for iOS v1.5

Downloader makes it easy to implement file download functionality.


Add files to your xCode project.

Usage Example

Let say we have a UIViewController called MyViewController and we would like to use downloader there.

First add this classes to your xCode project.

Then inside MyViewController.h define a global downloader variable and attach downloader delegate protocol.

@interface MyViewController : UIViewController <URLDownloaderDelegate>
    URLDownloader *downloader;

In your MyViewController.m file first import some librarie, setup downloader property and syntesize it.

#import "URLCredential.h"
#import "URLDownloader.h"
@interface MyViewController()
@property (retain) URLDownloader *downloader;
@synthesize downloader;

We then initialize downloader variable.

- (void)dealloc
    [downloader release];
    [super dealloc];

- (void)viewDidLoad
    [super viewDidLoad];
    self.downloader = [URLDownloader downloaderWithDelegate:self];

And finally we can define methods for starting and stopping download.

- (void)startDownload
    NSString *username = @"myuser";
    NSString *password = @"mypass";
    URLCredential *credential = [URLCredential credentialWithUsername:username andPassword:password];

    NSURL *url = [NSURL URLWithString:@""];
    NSURLRequestCachePolicy policy = NSURLRequestUseProtocolCachePolicy;
    NSTimeInterval timeout = 60.0;
    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:policy timeoutInterval:timeout];

    [self.urlDownloader download:request withCredential:credential];

- (void)stopDownload
    [self.downloader cancel];

Don't forget to implement method required by the URLDownloaderDelegate protocol.

# Required
- (void)urlDownloader:(URLDownloader *)downloader didFinishWithData:(NSData *)data;
- (void)urlDownloader:(URLDownloader *)downloader didFailOnAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
- (void)urlDownloader:(URLDownloader *)downloader didFailWithError:(NSError *)error;
- (void)urlDownloader:(URLDownloader *)downloader didFailWithNotConnectedToInternetError:(NSError *)error;

- (void)urlDownloader:(URLDownloader *)downloader didReceiveData:(NSData *)data;
- (void)urlDownloader:(URLDownloader *)downloader didChangeState:(URLDownloaderState)state;