ASIHTTPRequest-multiple request

I am developing an application that will request the image URL of some users from Facebook servers, but I do not know how many users I have (maybe 2 or maybe 20). Should I use ASIHTTPRequestwith loop and synchronous request or with graph API (using Facebook SDK for iOS) with loop?

+3
source share
1 answer

Trying to use ASINetworkQueue. This will allow you to create an ASIHTTPRequests queue that can be run asynchronously. for instance

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

    [imageArray addObject:image];
}

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

All Articles