• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting Internet (w/code, part 1)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Detecting Internet (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Simplest Dongle Method? Making a file uncopyable on CD?
  • Next by Date: Re: Detecting Internet (w/code, part 2)
  • Previous by thread: Re: Detecting Internet
  • Next by thread: Re: Detecting Internet
  • Index(es):
    • Date
    • Thread