AFNetworking and Reachability: Why is the request not executed after renewal?

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) {
       //Parse data...
   } 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?

+3
source share
4 answers

operationQueuea AFURLSessionManageris only used for callback delegate (see. documentation in the header).

, , , operationQueue .

.

+1

, .

Infact: AFNetworking , , , ( , ).

: , ? IP- ? , , wifi, , - .

-, AFNetworking, -. , , Wi-Fi-, (, IP-).

0

AFNetworkReachabilityManager AppDelegate.m. , , , . , , :

- (void)applicationDidBecomeActive:(UIApplication *)application {

   [[AFNetworkReachabilityManager sharedManager] startMonitoring];

   // Rest of your code here
}

:

:

NSOperationQueue * operationQueue = [[NSOperationQueue alloc] init];
[operationQueue addOperation:manager.operationQueue];
[manager.operationQueue release]; // as i have read you must do this release, but not sure
// rest of your code here

, , , , : http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues

2:

, , , , AFNetworking 2.0.

, , enqueue, :

if ([AFNetworkReachabilityManager sharedManager].reachable) {
   NSOperationQueue *operationQueue = manager.operationQueue;
}

, .

0

? Reachability Xcode 5, ( , Offline , , )

0

All Articles