Reputation: 6565
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?
Upvotes: 14
Views: 13720
Reputation: 65389
You could install Apple's Network Link Conditioner
On Yosemite:
Network Link Conditioner can be found in the "Hardware IO Tools for Xcode" package. This can be downloaded from the Apple Developer Downloads page. Once the download has finished, open the DMG and double-click "Network Link Condition.prefPane" to install (source).
With this preferences panel you could create a profile with 0kbps speed.
On older versions of OSX:
Mountain Lion / Mavericks: Xcode > Open Developer Tool > More Developer Tools
Lion: /Developer/Applications/Utilities/Network Link Conditioner
Upvotes: 12
Reputation: 207
Searching for similar need i.e. simulating a lossy wifi network connection on real device, I figured out how to do it :) I connected my MacBook Pro on ethernet and shared my Wifi connection to the device. Using Apple's Network Link Conditioner Prefpane then let me played with the connection quality. Very useful to simulate 3G, Edge and other baudrate.
Next step : find and buy a usb wifi adapter working on MAC OS X to let all of us (developpers team) to test without wiring each computer to ethernet.
Hope this will help some of you.
Upvotes: 0
Reputation: 1
Use Charles Web Proxy You can inspect all HTTP/S requests your app sends and responses it receives, throttle connection to simulate any network speed. Create custom throttle profile called "Disconnected" with Bandwidth = 0, to simulate network disconnections.
Upvotes: 4
Reputation: 5969
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.
Upvotes: 2
Reputation: 2546
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.
Upvotes: 4
Reputation: 13433
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.
Upvotes: 13
Reputation: 2408
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.
Upvotes: 19