I am using AFNetworking registering new users, it all works ok but on the following block I have some issues:
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:myRequest] autorelease];
operation.completionBlock = ^ {
if ([operation hasAcceptableStatusCode]) {
NSLog(@"success");
username.backgroundColor = [UIColor yellowColor];
} else {
switch ([operation.response statusCode]) {
case 421:
{
NSLog(@"Username taken.");
username.backgroundColor = [UIColor yellowColor];
}
break;
default:
break;
}
}
};
Basically I my server side script does some validation and fires back a HTTP status code (I know 421 isn't a valid one). This enables me to know what went wrong on the server, this works well.
My issue is that when the response comes back it fires the NSLog(@"success");
or NSLog(@"Username taken.");
straight away but any other codes fires of quite a few seconds later.
Can anyone shed any light on this please?
Here is the solution to my problem, this is much better and a hell of a lot faster:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"success: %@", operation.responseString);
[SVProgressHUD dismissWithSuccess:@"Sucess!" afterDelay:2];
[self saveContinue:operation.responseString];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", operation.responseString);
}
];
I hope this help people.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With