On Jan 25, 2010, at 1:50 PM, Laurent Daudelin wrote:
What is the best way to detect that there is no internet connection from my Cocoa app?
SystemConfiguration.framework. It can even send you notifications in real-time as the network status changes.
Detecting no network would work too but I'd like to be able even if the Macintosh is connected to a network that it can't reach the internet. I know I could use a test connection but is there a better way?
A reasonable request, but the problem is that "reach the internet" is too vague a question. The main situation where it breaks down is on an intranet that requires use of a proxy to reach the outside world. In this case you are literally not connected to the Internet, even with a 1000baseT plug jacked into your computer, even though your web browser and email work fine.
If on the other hand you just mean "can I ping the router", this will be true on a home 802.11 network even when the DSL/cable modem is down, and there are no outside hosts reachable.
Basically you have to decide based on the specific functionality of your app. In a lot of cases what the app wants to know is "can I reach my server at foobar.com:12345?", and SystemConfiguration will let you ask that question. It won't be 100% accurate, though, because it gets its answer only from consulting the local routing tables, not from actually sending any packets.
—Jens_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com