2

Possible Duplicate:
Easiest way to determine whether iPhone internet connection is available?

Hi guys, I'm developing an iPhone app. It works totally with internet.

When I run my app, how can I check if internet is active and it works correctly? And if it's not I would to show a popup.

Thanks.

Community
  • 1
  • 1
Joaquin McCoy
  • 425
  • 2
  • 7
  • 16

3 Answers3

4

Be aware that Reachability is (in my opinion) a misnomer.

Reachability, including reachabilityWithHostName (as in Apple's example) only indicates whether the device has an available internet connection with which to reach the outside world.

IMPORTANTLY: it does not indicate whether the specified host is actually up and running.

To find out whether the remote host is actually up and running, you'll need to initiate a connection to the remote host and handle a timeout in the case that it is not.

Snips
  • 6,575
  • 7
  • 40
  • 64
0

There's no such thing as "Internet". There exists large number of computers and other hardware, linked together. Now, if you need a particular host, you can ping it (also in code, don't know if iPhone lets you do this, though). If you need to ensure that particular service on the particular host is up and running, your only option is to send a request and check the response.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
  • "Internet" or "the Internet" is a something that exists and even thought some host may not be reachable you are still connected to the Internet. You can find more info in [the usual place](http://en.wikipedia.org/wiki/Internet) – João Portela Sep 03 '11 at 12:07
0

Another vote for Apple's reachability example code here.

Note it's important to get this right - apparently it's grounds for app rejection if you provide a misleading error message relating to networking. For example if you say you could not reach myhost.com when in fact it's because there is no network connection.

Andrew Ebling
  • 10,175
  • 10
  • 58
  • 75