开发者

ASIHTTPRequest-multiple request

开发者 https://www.devze.com 2023-03-10 00:56 出处:网络
I am developing an app that will request the profile picture URL of some users from Facebook servers, but I don\'t know how ma开发者_StackOverflowny users I will have (it might be 2 or it might be 20)

I am developing an app that will request the profile picture URL of some users from Facebook servers, but I don't know how ma开发者_StackOverflowny users I will have (it might be 2 or it might be 20). Should I use ASIHTTPRequest with a loop and a synchronous request, or the API graph (with Facebook SDK for iOS) with a loop?


Trying using ASINetworkQueue. It will allow you to create a queue of ASIHTTPRequests 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]];

    [imageArray addObject:image];
}

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号