forum

Home / DeveloperSection / Forums / How to check for an active Internet Connection on iPhone SDK?

How to check for an active Internet Connection on iPhone SDK?

Anonymous User164225-Apr-2015
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?

Updated on 25-Apr-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By