Sometimes a POST request with AFHTTPSessionManager executes the failure block with the following error: The network connection was lost. BUT the server side code executes successfully, sending a 200 OK response. How is that possible and what to do about it? What is a good strategy in general if a network connection is lost while the server executes a routine (successfully)? Could it be a problem with the AFNetworkReachabilityManager? I have it set up like this in the AppDelegate:
// Monitor network connection
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusReachableViaWWAN:
case AFNetworkReachabilityStatusReachableViaWiFi:
DDLogInfo(@"AFNetworkReachabilityStatusReachableViaWiFi:");
// Resume callbacks for remote operations
[[[TSHTTPSessionManager sharedManager] operationQueue] setSuspended:NO];
// Notify app
[[NSNotificationCenter defaultCenter] postNotificationName:TSDidConnectToNetworkNotification
object:self userInfo:nil];
break;
case AFNetworkReachabilityStatusNotReachable:
DDLogInfo(@"AFNetworkReachabilityStatusNotReachable:");
// Suspend callbacks for remote operations
[[[TSHTTPSessionManager sharedManager] operationQueue] setSuspended:YES];
// Notify app
[[NSNotificationCenter defaultCenter] postNotificationName:TSDidDisconnectFromNetworkNotification
object:self userInfo:nil];
break;
default:
break;
}
}];
EDIT: I guess I did not make myself clear: The question is not about AFNetworkReachabilityManager (I just added the code to show how the app detects connectivity issues and forwards them as notifications such that other parts of the app get notified if they decide to do so). The questions is about a request (POST) which is transmitted successfully to the server which causes the server side code to execute. At the same time, and before the server is able to send its response, the connection is lost, which in turn causes the client side failure block to execute (after the network is reachable again but that does not really make a difference I guess). How do I know on the client side that the server succeeded nonetheless?