Re: detecting no internet connection
Re: detecting no internet connection
- Subject: Re: detecting no internet connection
- From: Andrew Merenbach <email@hidden>
- Date: Sat, 8 Dec 2007 11:38:58 -0800
On Dec 8, 2007, at 9:32 AM, David LeBer wrote:
On 8-Dec-07, at 12:14 PM, Denise Eatherly wrote:
Hi,
Does anyone know a good way to detect whether a user has an
internet connection? NSURL does the right thing unless there is an
active airport with no connection. I tried using NSURLRequest.
That is a little better, but it doesn't seem to make any difference
what number I use for the timeout value. It seems to try for an
awfully long time before it gives up. Any suggestions are greatly
appreciated.
I'm currently using something like this:
- (BOOL) isNetworkAvailable
{
BOOL result = NO;
SCNetworkConnectionFlags flags;
NSString *network;
network = someNetwork; // assume exists
if ( SCNetworkCheckReachabilityByName([network cString], &flags) )
{
result = !(flags & kSCNetworkFlagsConnectionRequired) &&
(flags & kSCNetworkFlagsReachable);
}
return result;
}
;david
--
David LeBer
Hi,
Note that the use of -[NSString cString] is rather deprecated at the
moment (as of OS X 10.4), in favor of - (const char
*)cStringUsingEncoding:(NSStringEncoding)encoding.
Cheers,
Andrew
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden