Warten auf Abschluss-block komplett in ein AFNetworking Anfrage

Mache ich eine JSON-Anforderung mit AFNetworking und rufen Sie dann [operation waitUntilFinished] zu warten auf die operation und den Erfolg oder Misserfolg Blöcke. Aber, es scheint zu fallen, stimmt allerdings - in Bezug auf die log-Meldungen, die ich bekomme "0", "3", "1" statt "0", "1", "3"

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://google.com"]];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
httpClient.parameterEncoding = AFFormURLParameterEncoding;
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"query", @"q", nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET" path:[url path] parameters:params];
NSLog(@"0");
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *innerRequest, NSHTTPURLResponse *response, id JSON) {
 NSLog(@"1");
 gotResponse = YES;
} failure:^(NSURLRequest *innerRequest, NSHTTPURLResponse *response, NSError *error, id JSON) {
  NSLog(@"2");
  gotResponse = YES;
}];
NSLog(@"Starting request");
[operation start];
[operation waitUntilFinished];
NSLog(@"3");
  • Es scheint, als ob der Aufruf [operation waitUntilFinished] wartet nicht auf den Abschluss blockiert. AFJSONRequestOperation.m führt Sie mit dispatch_async denen ich denke, dass wird Teil eines separaten Betrieb. Ist das richtig und gibt es da einen Weg drumherum?
InformationsquelleAutor Kamran | 2012-05-20
Schreibe einen Kommentar