tags:

views:

24

answers:

1

Hi, Does anybody has a simple and easy understandable application on ASIHtttpRequest.

A: 

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

dododedodonl