Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetworking and Reachability: Why request fail after resume?

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?

like image 793
Foriger Avatar asked Nov 23 '25 02:11

Foriger


1 Answers

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.

like image 165
Vytis Avatar answered Nov 24 '25 18:11

Vytis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!