I use AFHTTPSessionManagerto send requests to the server and use the Reachability logic to check for a connection.
The code for the request is simple:
[manager POST:urlString parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"Error: %@", error);
}];
In addition, there is code that checks for availability, as an example on GitHub:
NSOperationQueue *operationQueue = manager.operationQueue;
[manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusReachableViaWWAN:
case AFNetworkReachabilityStatusReachableViaWiFi:
[operationQueue setSuspended:NO];
break;
case AFNetworkReachabilityStatusNotReachable:
default:
[operationQueue setSuspended:YES];
break;
}
}];
When the status (from AFNetworkReachabilityStatusNotReachableto AFNetworkReachabilityStatusReachableViaWiFi) changes and the request resumes, why is the fault block executed? What is the reason for this? Am I doing something wrong?
source
share