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:
I hope this help people.