© 2013 All rights reserved.
0

How to check for an active Internet Connection on iPad (iPhone) SDK

Sometimes, you need to find out whether your application is connected to the Internet. Is again a few possibilities, but not all are correct.

Test open web page

Simple solution is to try visit a website. Where you can download the content, we have connection to internet.

This method is not bad, but unfortunately the function stringWithContentsOfURL is deprecated.

Use Reachability class

Second solution is use “Reachability” class from apple (http://goo.gl/kSHn3) and implement internet checking with this.

In this case we’ll download Reachability.m and Reachability.h and add this class into our project.

Now we can create a wrapper for example, which will examine information about the connection


File Internet.h

File Internet.m

Now we have three static functions which return information about internet connection.

Possible problems

It is possible that your application does not compile, and you get an error:

This fix quite easily, disabling automatic reference in the project:



internet possible

Last error which you can see is:

Repair is again simple, just add into the header file Reachability.h this line:

Comments are closed for this page

About
Hi, i am programmer from the Czech Republic. I love web development (Ruby, Ruby on Rails, PHP, Nette) and iOS development (Objective-C, Cocoa).
To cooperate, here is my phone:
+420 608 836