Ich habe eine verschachtelte Schleife des Sendens der Anfrage.NSURLConnection senden Anfrage nach Abschluss aller Prozess
-(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.
}
Das Problem ist, dass ich "-(void) connectionDidFinishLoading:(NSURLConnection *) connection"
zuerst, bevor die Anfrage senden wieder in der for-Schleife eingeben möchten.
Aber im Moment wird die for-Schleife beendet und alle Anfragen vor der Eingabe an "-(void) connectionDidFinishLoading:(NSURLConnection *) connection"
gesendet.
[NSURLConnection sendSynchronousRequest: Anfrage returningResponse: Antwortfehler: nil] –
Sie können NSOperationQueue mit addDependency oder MaxConcurrentOperation verwenden. –
@PKT Ich denke, Ihre Lösung ist genug für mich. Danke – user1151874