Yield to the run loop for a tenth of a second to allow the network reachability observer to be scheduled. This prevents issues where requests dispatched from an app delegate are denied access to the network.

This commit is contained in:
Blake Watters
2011-01-03 13:23:14 -05:00
parent e7ac2b4577
commit e49d8462a9

View File

@@ -133,6 +133,11 @@ static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReach
if (NO == SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) {
NSLog(@"Warning -- Unable to schedule reachability observer in current run loop.");
}
// Fire the run loop to allow the observer to be scheduled. This ensures that requests fired
// after the observer is scheduled, but before control is yieled to the run loop are not mistakenly
// denied dispatching because no network availbility can be determined.
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
}
}