我有一个发送请求的嵌套循环。NSURLConnection在完成所有处理后发送请求
-(void) download
{
for(NSString *id in array)
{
//init with request and start the connection
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request deletegate:self];
[conn start];
}
}
-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data
{
//enter here secondly
}
-(void) connectionDidFinishLoading:(NSURLConnection *) connection
{
//enter here last, after finish the for loop
//my intention is use the downloaded data to do something before sending a new request.
}
的问题是,我想进入"-(void) connectionDidFinishLoading:(NSURLConnection *) connection"
先在再次发送请求循环之前。
但目前它会完成for循环并发送所有请求,然后输入到"-(void) connectionDidFinishLoading:(NSURLConnection *) connection"
。
[NSURLConnection sendSynchronousRequest:request returningResponse:Response error:nil] –
您可以使用带有addDependency或MaxConcurrentOperation的NSOperationQueue。 –
@PKT我认为你的解决方案对我来说已经足够了。谢谢 – user1151874