Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Nick Sint
Nick Sint
4,208 Points

Network/Internet connection - Best way to detect?

Hi all,

I was hoping to get some feedback in terms of what is the best way to test whether a user has internet connection before a method which relies on a internet connection is implemented.

I have found 3 different ways to do this:

  1. Try to access data from a website with typically has a quick-response time like google
NSString *testConnection = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://google.co.uk"] encoding:NO error:nil];

if (testConnection != nil) { 
     //There is an active internet connection
}else {
    //There is NOT an active internet connection
}
  1. Using the built-in Reachability Class xcode provides (although i believe this is now outdated)

  2. Using tonymillion's Reachability Class

https://github.com/tonymillion/Reachability

1 Answer

Stone Preston
Stone Preston
42,016 Points

I use tony millions class. works well for me