Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting Internet




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.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
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

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



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.