-
Notifications
You must be signed in to change notification settings - Fork 30
ACHTTPDownloader
#What is ACHTTPDownloader? This component is used to download large files. Generally, ACHTTPRequest should be used for smaller files since the response is assembled in memory and then parsed into a meaningful format. In some cases, the files you download may be large and it makes more sense to write the response directly to a file. This is where the ACHTTPDownloader component comes in.
##Sample Code In the spirit of ACHTTPRequest, ACHTTPDownloader aims to be as concise as possible. To download a file, you simply write one line of code like this:
[ACHTTPDownloader download:@"http://my.domain.com/contents/bigvideo.mov" toPath:@"/path/to/save/to"
delegate:self action:@selector(finishDownloading:)];
Similar to ACHTTPRequest, you write a method to do something else with the results of the download.
-(void)finishDownloading:(ACHTTPDownloader*)downloader {
if([downloader isKindOfClass:[NSError class]]) {
NSLog(@"Error: %@", downloader);
}
NSLog(@"Saved to: %@", downloader.finalPath);
}
Just like ACHTTPRequest, you can also just set a delegate and not an action selector. This will require your code to implement the ACHTTPDownloaderDelegate. You can then implement these methods to handle the downloading process. One advantage to this method is that you can update a progress indicator:
-(void)httpDownloader:(ACHTTPDownloader*)httpDownloader downloadedToPath:(NSString*)path {
NSLog(@"Downloaded to %@", path);
}
-(void)httpDownloader:(ACHTTPDownloader*)httpDownloader failedWithError:(NSError*)error {
NSLog(@"Error %@", error);
}
-(void)httpDownloader:(ACHTTPDownloader*)httpDownloader updatedProgress:(NSNumber*)percentComplete {
progressBar.value = percentComplete;
}