Re: Detecting Internet (w/code, part 1)
Re: Detecting Internet (w/code, part 1)
- Subject: Re: Detecting Internet (w/code, part 1)
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Tue, 27 Jun 2006 09:56:45 +0200
On 27 Jun 2006, at 05:59, email@hidden wrote:
First I want to thank John for his example. It really helped me a lot.
I'll add just a few things, which might be useful (I hope).
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:
#import <SystemConfiguration/SystemConfiguration.h>
and add SystemConfiguration.framework in Xcodes Linked Framworks.
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");
instead of "www.apple.com" one might use:
"ntp"
"some.silly.name.asdfouasodfadi" or even:
"!%$#%@%$!#%$#@".
Not so good:
"123" or "53001".
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;
replace PSMAppController with the class of your NSapp delegate.
[self networkStatusChanged:flags];
}
I'm really just forwarding the flags to my app controller to work
with.
Part 2 to follow...
_______________________________________________
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