0

I've implemented this operation:

   [NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                if (connectionError) {
                    NSLog(@"Error %@ | contaShow %i",connectionError.description,_contaShow);
                    //OPERATIONS in case of error
                } else {
                   //OPERATIONS in case of success

Sometime, if occurs a connection error (ex. lost connection) I want execute the code inside the if block. With debug I can see that the code lines are called, but aren't executed!!!

Somebody can tell me why?!?

Thanks...

Blasco73
  • 2,980
  • 2
  • 24
  • 30

1 Answers1

0

If the connection returns an error code (e.g. 404), you'll likely go into the success case, because you need to also check the value of ((NSHTTPURLResponse *)response).statusCode to make sure it is 200.

Beyond that, make sure you're using a debug build. Otherwise, the debugger may lie to you about what lines of code are executing.

dgatwood
  • 10,129
  • 1
  • 28
  • 49