views:

1275

answers:

4

Apple wants me to give the user a friendly apology if I can't find an internet connection. Using the Reachability Demo, this was easy enough. I want to take it a step further and monitor for a connection loss. The demo has this functionality, but I can't figure out how to shut my connection off to test if it works.

How would I go about simulating a loss of (or actually losing) a connection?

+9  A: 

If you're developing in the iPhone Simulator, simply disconnect your computer from the internet. If your computer has no network access, neither does the iPhone Simulator.

To test on the device, you can do the following:

First, setup a WiFi router that you can use for testing.

You can turn on Airplane mode on the phone, then turn WiFi back on. This will prevent the 3G connection from providing data access.

Launch your application. Now you can simply disconnect your WiFi router to simulate a loss of connectivity.

Joey Hagedorn
or try a faraday cage? http://en.wikipedia.org/wiki/Faraday_cage
russau
I normally wear a tin hat, so the cage is a natural progression. hehThanks Joey, I wanted to test on the device. Cheers.
Joel Hooks
+3  A: 

You can use the SpeedLimit preference pane to simulate network latency under the simulator. And here's a command line version built on top of the ipfw command.

The advantage over just yanking the cord or killing WiFi is that you can specify the speed when hitting specific hosts so it can be used for testing without killing your regular network services.

Ramin
+4  A: 

For testing in the simulator I make great use of Little Snitch. It's a very useful application for writing rules as to what can communicate with the outside world and for how long.

It will also notify you if an application wishes to access the internet on the fly and you can temporarily restrict access for either that time, that session or forever.

As for testing on the device, I log into my wireless router and temporarily disable either the network or turn on restriction by MAC ID for the duration of the test.

Neosionnach
A: 

Perhaps this preference pane is also useful for you: SpeedLimit.prefPane it can't loose the connection, but you can slow down it based on the host and port you're trying to reach.

DASKAjA