- (IBAction )fetchThreeImages:(id )sender
{
//清空三个 imageview
[imageView1 setImage :nil ];
[imageView2 setImage :nil ];
[imageView3 setImage :nil ];
//初始化一个网 络连接对象
if (!networkQueue) {
networkQueue = [[ASINetworkQueue alloc ] init ];
}
failed = NO ;
[networkQueue reset ];// 重 设网络连接对象,如果代理灯一些设置
[networkQueue setDownloadProgressDelegate: test];// 设置下载进度条的代理
[networkQueue setRequestDidFinishSelector: @selector (imageFetchComplete:)];// 设置下载完成后,所调用的方法
[networkQueue setRequestDidFailSelector: @selector (imageFetchFailed:)];// 设置下载失败调用的方法
[networkQueue setShowAccurateProgress: YES ];// 是否 显示详细的进度,就是是否有一个连续的进入显示
[networkQueue setDelegate :self ];// 设置网络连接对象的代理
ASIHTTPRequest *request;
// 设置下载的地址
request = [ASIHTTPRequest requestWithURL :[ NSURL URLWithString : @"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"]];
// 设置下载的文件的保持路径
[request setDownloadDestinationPath:[[ NSHomeDirectory() stringByAppendingPathComponent: @"Documents" ] stringByAppendingPathComponent: @"1.png" ]];
// 设置用于下载显示的进入的进度条
[request setDownloadProgressDelegate: imageProgressIndicator1];
[request setUserInfo:[NSDictionary dictionaryWithObject :@"request1" forKey :@"name" ]];
//添加 这个下载
[networkQueue addOperation :request];
// 同上
request = [[[ASIHTTPRequest alloc ] initWithURL :[ NSURL URLWithString : @"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"]] autorelease ];
[request setDownloadDestinationPath:[[ NSHomeDirectory() stringByAppendingPathComponent: @"Documents" ] stringByAppendingPathComponent: @"2.png" ]];
[request setDownloadProgressDelegate:imageProgressIndicator2];
[request setUserInfo:[NSDictionary dictionaryWithObject :@"request2" forKey :@"name" ]];
[networkQueue addOperation :request];
// 同上
request = [[[ASIHTTPRequest alloc ] initWithURL :[ NSURL URLWithString : @"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]] autorelease ];
[request setDownloadDestinationPath:[[ NSHomeDirectory() stringByAppendingPathComponent: @"Documents" ] stringByAppendingPathComponent: @"3.png" ]];
[request setDownloadProgressDelegate:imageProgressIndicator3];
[request setUserInfo:[NSDictionary dictionaryWithObject :@"request3" forKey :@"name" ]];
[networkQueue addOperation :request];
//开始下 载
[networkQueue go];
}
以上部分文字来自于:www.iosdk.com.