Re: Detecting Internet (w/code, part 1)
Re: Detecting Internet (w/code, part 1)
- Subject: Re: Detecting Internet (w/code, part 1)
- From: John Pannell <email@hidden>
- Date: Mon, 26 Jun 2006 17:42:48 -0600
Hi all-
I sent Gerriet a reply that was too large for the list (perhaps I
need to write more concise code?) and thought I'd send it in pieces,
as it was something I had wished someone had written out for me.
Detecting Internet changes follows:
1. Register for network change notifications when your app launches
(I did it in applicationDidFinishLaunching)...
// register for network notifications
SCNetworkReachabilityRef target =
SCNetworkReachabilityCreateWithName(NULL, "www.apple.com");
SCNetworkReachabilityContext reachabilityContext = {
.version = 0,
.info = self,
.retain = CFRetain,
.release = CFRelease,
.copyDescription = CFCopyDescription,
};
SCNetworkReachabilitySetCallback(target, NetworkStatusChanged,
&reachabilityContext);
SCNetworkReachabilityScheduleWithRunLoop(target, [[NSRunLoop
currentRunLoop] getCFRunLoop], kCFRunLoopDefaultMode);
NetworkStatusChanged() is my callback function that will now get
called when something changes with the networking. Note also that
I'm passing in a reference to self (which is my app controller) in
the reachability context, which will make it easier/possible to
message an object from the C callback function.
2. Write your callback...
void NetworkStatusChanged(SCNetworkReachabilityRef target,
SCNetworkConnectionFlags flags, void *info)
{
PSMAppController *self = info;
[self networkStatusChanged:flags];
}
I'm really just forwarding the flags to my app controller to work with.
Part 2 to follow...
John
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden