现在的位置: 首页 > 综合 > 正文

ASIHTTPRequest使用介绍

2018年07月26日 ⁄ 综合 ⁄ 共 2133字 ⁄ 字号 评论关闭
使用实例:

- (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];

}

抱歉!评论已关闭.