0

How and where in the code can handle responses from the server when requests using AFNetworking? Can't find detailed and full example.

Interested in situation:

  1. exceeded the timeout of the response (for example, 5 seconds, the server is not responding due to bad Internet)

  2. there is no Internet at all

  3. error in the script on the remote server

  4. internal server error / prevention.. etc. Most of the most common causes.

I just want to show different AlertView depending on the response code from server.

Example query:

NSString * URL = @"http://supersite.ru/script.php";
NSURL * nsURL = [NSURL URLWithString:URL];
NSURLRequest *request = [NSURLRequest requestWithURL:nsURL];
AFHTTPRequestOperation *operationFeedback = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operationFeedback.responseSerializer = [AFJSONResponseSerializer serializer];
[operationFeedback setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id JSONResponse){

// ... then handling the response

} failure:^(AFHTTPRequestOperation *operation, NSError *err)
{

// ... and then probably need to handle the response code?!

}];
[operationFeedback start];
FormigaNinja
  • 1,571
  • 1
  • 24
  • 36
Evgeny Fedin
  • 198
  • 2
  • 11
  • 1
    http://stackoverflow.com/questions/8469492/is-there-an-easy-way-to-get-the-http-status-code-in-the-failure-block-from-afhtt – Mindeater Jun 03 '15 at 02:55
  • Thank u. So, there is no internet connection status will be zero? RIght? Also need to know how to set timeout... about 5 sec. – Evgeny Fedin Jun 03 '15 at 03:00
  • http://stackoverflow.com/questions/8304560/how-to-set-a-timeout-with-afnetworking – Mindeater Jun 03 '15 at 03:06

0 Answers0