Realizo una solicitud JSON con AFNetworking y luego llamo a [operation waitUntilFinished] para esperar la operación y los bloques de éxito o falla. Sin embargo, parece caer directo, aunque - en cuanto a los mensajes de registro, recibo "0", "3", "1" en lugar de "0", "1", "3"Esperando completar el bloque de finalización en una solicitud de AFNetworking
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");
Parece que la llamada a '[operation waitUntilFinished]' no espera en los bloques de finalización. AFJSONRequestOperation.m los ejecuta con 'dispatch_async', que creo que se convierte en parte de una operación separada. ¿Es correcto y hay una forma de evitarlo? – Kamran