Re: Problems detecting an active internet connecting using SystemConfiguration
Re: Problems detecting an active internet connecting using SystemConfiguration
- Subject: Re: Problems detecting an active internet connecting using SystemConfiguration
- From: Andrew Frezell <email@hidden>
- Date: Mon, 17 Mar 2003 10:43:35 -0500
The problem with hardcoding a URL is that you assume the hardcoded URL
is active...access to the site may be blocked by a firewall or any
number of problems. You really need to be able to test the interface
(modem, airport, ethernet) for activity.
Drew
On Saturday, March 15, 2003, at 02:47 PM, Alex wrote:
If all you want to know is if you are online or not I think this is
easier:
-(IBAction)areWeLive:(id)sender
{
([NSString stringWithContentsOfURL:[NSURL
URLWithString:@"http://www.apple.com"]]) ? NSLog(@"We are
online"):NSLog(@"We are offline");
}
Am Samstag, 15.03.03, um 10:37 Uhr (US/Pacific) schrieb David Sinclair:
Von: David Sinclair <email@hidden>
Datum: Sa, 15. Mrz 2003 10:37:28 US/Pacific
An: Marc Weil <email@hidden>
Cc: Cocoa Digest <email@hidden>
Betreff: Re: Problems detecting an active internet connecting using
SystemConfiguration
On Saturday, Mar 15, 2003, at 05:40 US/Pacific, Marc Weil wrote:
I have been trying to use SCNetwork.h's
SCNetworkCheckReachabilityByName()
function for detecting an active internet connection, but it doesn't
seem to
work right. It only worked correctly once (unless I am misreading
what its
constants mean).
It took some experiments for me to figure out a good combination that
seems to work in all tested cases -- DSL, AirPort, dial-up, waking
from sleep, etc.
Here are some values I've encountered:
Ethernet DSL unplugged: 0 = 00000000 = all off
Ethernet DSL online: 2 = 00000010 = kSCNetworkFlagsReachable on
AirPort waking (offline): 7 = 00000111 =
kSCNetworkFlagsTransientConnection &
kSCNetworkFlagsReachable &
kSCNetworkFlagsConnectionRequired
Dialup online: 11 = 00001011 =
kSCNetworkFlagsTransientConnection &
kSCNetworkFlagsReachable &
kSCNetworkFlagsConnectionAutomatic
Here's the method I use in my Dejal Simon product, that seems to cover
all cases. I check two sites just in case the first one is
unavailable for some reason:
- (BOOL)internetOnline
{
Boolean success;
BOOL okay;
SCNetworkConnectionFlags status;
success = SCNetworkCheckReachabilityByName("www.apple.com",
&status);
okay = success && (status & kSCNetworkFlagsReachable) && !(status
& kSCNetworkFlagsConnectionRequired);
if (!okay)
{
success = SCNetworkCheckReachabilityByName("www.w3.org",
&status);
okay = success && (status & kSCNetworkFlagsReachable) &&
!(status & kSCNetworkFlagsConnectionRequired);
}
return okay;
}
Hope this helps.
--
David Sinclair, Dejal Systems, LLC - email@hidden
Let Dejal Simon keep an eye on your sites for changes or failures!
http://www.dejal.com/simon/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.