How to check for an active Internet Connection on iPhone SDK?
Posted
by
Brock Woolf
on Stack Overflow
See other posts from Stack Overflow
or by Brock Woolf
Published on 2009-07-05T08:45:01Z
Indexed on
2011/01/13
18:53 UTC
Read the original article
Hit count: 238
I would like to check to see if I have an Internet connection on the iPhone using the Cocoa Touch libraries.
I came up with a way to do this using an NSUrl. The way I did it seems a bit unreliable (because even Google could one day be down and relying on a 3rd party seems bad) and while I could check to see for a response from some other websites if Google didn't respond, it does seem wasteful and an unnecessary overhead on my application.
- (BOOL) connectedToInternet
{
NSString *URLString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"]];
return ( URLString != NULL ) ? YES : NO;
}
Is what I have done bad? (Not to mention 'stringWithContentsOfURL' is deprecated in 3.0) And if so what is a better way to accomplish this?
© Stack Overflow or respective owner