ASIHttpRequest上是否有任何正文应用程序

时间:2010-08-13 12:12:17

标签: iphone xcode

在ASIHtttpRequest上是否有人有一个简单易懂的应用程序。

1 个答案:

答案 0 :(得分:1)

这是为了下载youtube视频

#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

我将下载的内容直接保存到目的地......

http://allseeing-i.com/ASIHTTPRequest/How-to-use