-(void)installNetworkListener{
SCNetworkReachabilityContext context = {0, ( void *)CFBridgingRetain(self), nil, nil, nil};
self.connection = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault,
if (SCNetworkReachabilitySetCallback(self.connection, networkStatusDidChange, &context) &&
SCNetworkReachabilityScheduleWithRunLoop(self.connection, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) {
}
}
My callback looks like this:
static BOOL networkingOK;
static void networkStatusDidChange(SCNetworkReachabilityRef target, SCNetworkConnectionFlags flags, void* info){
Boolean reachable = flags & kSCNetworkFlagsReachable;
Boolean connectionRequired = flags & kSCNetworkFlagsConnectionRequired;
networkingOK = reachable && (!connectionRequired);
NSLog(@"Can we connect? %@", networkingOK ? @"Yes" : @"Nope");
if(networkingOK){
NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
[center postNotificationName:WV_NETWORKING_OK object:nil userInfo:nil];
}
}
It all works just fine, I just have no idea how to test it.
Thanks
"Yes Virginia, there is a Chaminade"
--unknown
Lorenzo Thurman