On Jun 26, 2006, at 3:20 PM, Gerriet M. Denkmann wrote:
I have an app which needs to get informed of changes in internet
connectivity.
Currently I am doing:
- (void)timerInterrupt: (NSTimer *)theTimer ; // called every second
{
BOOL nowConnected = [ NSHost hostWithName:
@"time.asia.apple.com" ] != nil ;
if ( nowConnected == connected ) return;
connected = nowConnected;
if ( connected ) [ self startOfConnection ] else [ self
endOfConnection ] ;
}
This works, but it somehow does not look very nice.
1. is there a better way to detect an internet connection than
hostWithName ?
2. is there a better way to get startOfConnection and
endOfConnection ?
Check out the functions in SCNetworkReachability.h (part of the
SystemConfiguration framework).
I used those APIs in a small test app about 2 years ago. I never
shipped any app with that code, but from what I remember, it worked
great. I would get notifications when I connected/disconnected my
modem.
There may be other APIs (in Carbon and/or Cocoa) that perhaps are
layers over the SC API. Not sure though.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden