I think I figured out the issue. Looks like AFNetworking's callback mechanism doesn't work as it should - check out AFNetworkReachabilityManager's startMonitoring
method: there's an:
if (strongSelf.networkReachabilityStatusBlock) {...
which seems to fail no matter if you've set up a callback or not.
To fix this, I've added the following method to AFNetworkReachabilityManager:
- (void)startMonitoringWithStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block
{
[self stopMonitoring];
if (!self.networkReachability) {
return;
}
__weak __typeof(self)weakSelf = self;
AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf.networkReachabilityStatus = status;
if (block) {
block(status);
}
};
SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context);
SCNetworkReachabilityFlags flags;
SCNetworkReachabilityGetFlags(self.networkReachability, &flags);
dispatch_async(dispatch_get_main_queue(), ^{
AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
callback(status);
});
SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
}
This basically does the same thing but references the block from the method parameter rather than from the reachability manager's property.