I use AFHTTPSessionManager for sending requests to a server, and use Reachability logic to check if there is a connection.
The code for the request is simple:
[manager POST:urlString parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
//Parse data...
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"Error: %@", error);
}];
Also, there is code that checks availability in manner like example in 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 status changes (AFNetworkReachabilityStatusNotReachable to AFNetworkReachabilityStatusReachableViaWiFi for example), and request is resumed, why failure block is executed? What is the reason for that? Am I doing something wrong?
operationQueue in AFURLSessionManager is only used for delegate callbacks (see documentation in the header).
I suspect the request is carried out when offline, but the callbacks are suspended and fire only when operationQueue is resumed.
However I haven't yet found a way to resume requests after coming online.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With