I have a problem when I test my application by turning flight mode on and off to handle intermittent or unstable connections.
Basically, I need to queue requests for submissions from the user and do it synchronously, if the request fails to get it out of the queue, inform the user about it, and then do the following. Adding operations can be many at a time or one at a time, regardless of when they need to stand in line and perform one at a time.
It works fine until the 3rd or 4th time, when I disconnected the connection, after that NSOperationQueue AFHTTPRequestOperationsit will not be executed, although I confirm that they are sitting in NSOperationQueue. I have my own task class, which contains AFHTTPRequestOperationas a property and in my lazy initializer I create a request.
Here is what I mostly do in code:
My custom class that contains the task and the manager (so the request can create itself in a lazy initializer).
@interface MyTask : NSObject
@property (nonatomic, strong) AFHTTPRequestOperation *request;
@property (nonatomic, strong) AFHTTPRequestOperationManager *manager;
@property (nonatomic, strong) NSString *name;
@end
Code inside the operations manager custom class that adds tasks dispatched using view dispatchers:
- (void)addNewRequest:(MyTask *)task {
[self.operationQueue addOperation:task.request];
}
Here's how I handle an online pause when pausing and resuming a queue:
__block NSOperationQueue *operationQueue = self.operationQueue;
__weak typeof(self) weakSelf = self;
[self.operationRequestManager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
__strong typeof(weakSelf) strongSelf = weakSelf;
switch (status) {
case AFNetworkReachabilityStatusNotReachable:
[strongSelf.networkHelper setNetworkActivityIndicatorVisible:NO];
[operationQueue setSuspended:YES];
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
[strongSelf.networkHelper setNetworkActivityIndicatorVisible:YES];
[operationQueue setSuspended:NO];
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
[strongSelf.networkHelper setNetworkActivityIndicatorVisible:YES];
[operationQueue setSuspended:NO];
break;
default:
[strongSelf.networkHelper setNetworkActivityIndicatorVisible:NO];
[operationQueue setSuspended:YES];
break;
}
}];
[self.operationRequestManager.reachabilityManager startMonitoring];
, Queue, operationCount. - .
maxConcurrency 1 opQueue .
- (NSOperationQueue *)operationQueue {
if (_operationQueue == Nil) {
_operationQueue = [[NSOperationQueue alloc] init];
[_operationQueue setMaxConcurrentOperationCount:1];
}
return _operationQueue;
}
ETA: operationQueue , , , .