Does anybody has a simple and easy understan开发者_高级运维dable application on ASIHtttpRequest.
This was meant to download youtube videos
#import "Downloader.h"
#import "ASIHTTPRequest.h"
@implementation Downloader
- (NSProgressIndicator*)startDownloadingUrl:(NSString*)downloadUrl fileName:(NSString*)fileName {
NSURL *url = [NSURL URLWithString:downloadUrl];
myProgressIndicator = [[NSProgressIndicator alloc] init];
[myProgressIndicator setMaxValue: 1];
NSString *destinationPath = [[NSString alloc] initWithFormat:@"%@/Downloads/%@.mp4", NSHomeDirectory(), fileName];
NSLog(@"Dest: %@", destinationPath);
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDownloadDestinationPath:destinationPath];
[request setDownloadProgressDelegate:myProgressIndicator];
[request startAsynchronous];
NSLog(@"Max: %f, Value: %f, %@", [myProgressIndicator maxValue],[myProgressIndicator doubleValue],[myProgressIndicator description]);
return myProgressIndicator;
}
- (void)requestFinished:(ASIHTTPRequest *)request {
// Use when fetching text data
NSLog(@"Download succesful...");
NSLog(@"Max: %f, Value: %f", [myProgressIndicator maxValue],[myProgressIndicator doubleValue]);
}
- (void)requestFailed:(ASIHTTPRequest *)request {
NSError *error = [request error];
NSLog(@"%@", error);
}
@end
I save the downloaded thing directly to a destination...
http://allseeing-i.com/ASIHTTPRequest/How-to-use
精彩评论