iPhone – AsiHttpRequest- multiple requests

I am developing an application which will request some users’ profile picture URL from Facebook server, but I don’t know how many users I will have (maybe 2 or maybe 20) .Should I use ASIHTTPRequest with loops and synchronous requests, or API graphics with loops (with Facebook SDK for iOS)?
Try using ASINetworkQueue. It will allow you to create ASIHTTPRequests queues that can still be started asynchronously. For example,

- (void)getImages
{
if(!self.queue)
self.queue = [[[ASINetworkQueue alloc] init] autorelease] ;

NSArray* urlStringsToRequest = [NSArray arrayWithObjects:@"http://www.example.com/image1.png",@"http://www.example.com/image2.png" ,nil];
for(NSString* urlString in urlStringsToRequest)
{
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url] ;
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[self .queue addOperation:request];
}

[self.queue go];
}

- (void)requestDone:(ASIHTTPRequest*) req
{
UIImage* image = [UIImage imageW ithData:[req responseData]];

[imageArray addObject:image];
}

- (void)requestWentWrong:(ASIHTTPRequest*)req
{
NSLog(@"Request returned an error %@",[req error]);
}

I am developing an application , It will request some user’s profile picture URL from Facebook server, but I don’t know how many users I will have (may be 2 or maybe 20). Should I use ASIHTTPRequest with loop and synchronous request, or API with loop Graphics (with Facebook SDK for iOS)?

Try using ASINetworkQueue. It will allow you to create ASIHTTPRequests queues that can still be started asynchronously. For example,

- (void)getImages
{
if(!self.queue)
self.queue = [[[ASINetworkQueue alloc] init] autorelease];

NSArray* urlStringsToRequest = [NSArray arrayWithObjects:@"http://www.example.com/image1.png",@"http://www.example.com/image2.png",nil];
for(NSString* urlString in urlStringsToRequest)
{
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[self.queue addOperation:request];
}

[self.queue go];
}

- (void)requestDone:(ASIHTTPRequest*)req
{
UIImage* image = [UIImage imageWithData:[req responseData]];

[imageAr ray addObject:image];
}

- (void)requestWentWrong:(ASIHTTPRequest*)req
{
NSLog(@"Request returned an error %@" ,[req error]);
}

Leave a Comment

Your email address will not be published.