【发布时间】:2016-08-21 06:34:37
【问题描述】:
我有一个发送请求的嵌套循环。
-(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.
}
问题是我想在for循环中再次发送请求之前先输入"-(void) connectionDidFinishLoading:(NSURLConnection *) connection"。
但目前它将完成for循环并将进入之前的所有请求发送到"-(void) connectionDidFinishLoading:(NSURLConnection *) connection"。
【问题讨论】:
-
[NSURLConnection sendSynchronousRequest:请求返回响应:响应错误:无]
-
您可以将 NSOperationQueue 与 addDependency 或 MaxConcurrentOperation 一起使用。
-
@PKT 我认为您的解决方案对我来说已经足够了。谢谢
-
@ArunGupta tq 无论如何都要为你提供帮助。
-
如果它适合你,让它正确,这样其他人也可以使用它......
标签: ios objective-c iphone nsurlconnection nsconnection