Let me first stress the fact that I'm talking about the Mac OS X SDK, not iPhone.
In order to determine the "connectivity" and get the flags, I do something similar to:
#import <SystemConfiguration/SystemConfiguration.h>
const char *hostName = [@"google.com" cStringUsingEncoding:NSASCIIStringEncoding];
SCNetworkReachabilityRef target = SCNetworkReachabilityCreateWithName(NULL, hostName);
SCNetworkConnectionFlags flags = 0;
SCNetworkReachabilityGetFlags(target, &flags);
Which is fine for just that -- getting info on the reachability of Google (which is exactly what I want to know).
Is there a way to add an observer to the changes? I've been looking into SCDynamicStore
, but I find the single example from Apple and the documentation a bit overwhelming.
Ideally I'd want to be able to set a function for flag changes, but this will suffice: notice when IP is "dropped"/released, and when it is obtained. (I could then do the reachability hardcoded in the function which is triggered on IP obtained).
Please don't hesitate to ask for elaborations.
if ((flags & kSCNetworkReachabilityFlagsIsDirect) == kSCNetworkReachabilityFlagsIsDirect)
andkSCNetworkReachabilityFlagsIsWWAN
kSCNetworkReachabilityFlagsIsDirect
. Trying to disconnect/reconnect/making the host unavailble in /etc/hosts doesn't push any notifications to my app at the moment. – Neumann