Estoy utilizando AFNetworking y estoy creando una solicitud posterior para la que necesito información json. El siguiente código funciona, sin embargo, tengo dos preguntas principales; ¿Dónde lanzo el ActivityIndicator Manager? La segunda pregunta es si este código es correcto, dado que soy nuevo, me confunden los bloques, así que realmente quiero saber si lo estoy haciendo bien para un rendimiento óptimo, aunque funciona.Solicitud de publicación de AFNetworking con comentarios de json
NSURL *url = [NSURL URLWithString:@"mysite/user/signup"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
AFNetworkActivityIndicatorManager * newactivity = [[AFNetworkActivityIndicatorManager alloc] init];
newactivity.enabled = YES;
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
usernamestring, @"login[username]",
emailstring, @"login[email]",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"mysite/user/signup"parameters:params];
[httpClient release];
AFJSONRequestOperation *operation = [AFJSONRequestOperation operationWithRequest:request success:^(id json) {
NSString *status = [json valueForKey:@"status"];
if ([status isEqualToString:@"success"]) {
[username resignFirstResponder];
[email resignFirstResponder];
[self.navigationController dismissModalViewControllerAnimated:NO];
}
else {
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Login Unsuccessful"
message:@"Please try again"
delegate:NULL
cancelButtonTitle:@"OK"
otherButtonTitles:NULL];
[alert show];
[alert release];
}
}
failure:^(NSHTTPURLResponse *response, NSError *error) {
NSLog(@"%@", error);
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Login Unsuccessful"
message:@"There was a problem connecting to the network!"
delegate:NULL
cancelButtonTitle:@"OK"
otherButtonTitles:NULL];
[alert show];
[alert release];
}];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
NSLog(@"check");
}
Muchas gracias por su ayuda de antemano :)
dónde viene el 'AFJSONRequestOperation operationWithRequest: éxito: Acabado:' Método ¿viene de? No lo veo en la API. –
@reakinator En realidad mencionó '+ JSONRequestOperationWithRequest: success: failure:' Vea el ejemplo [aquí] (https://github.com/AFNetworking/AFNetworking#readme). – borisdiakur