Simulate Network Outages in Your App with Little Snitch

Modern development tools are super-convenient. XCode’s more recent builds let you debug an iOS app over WiFi, so you don’t have to succumb to the indignity of plugging in a Lightning cable (so 2017). React Native’s tooling goes a step farther, giving you the ability to run the native part of the app on a mobile device and execute the JavaScript side part of the app in a web browser on your development machine (where the JS inspection tools are more convenient). Networked debugging is amazing.

But sometimes, you need to test your app’s response to network outages. Suddenly, all those networked debugging tools become kind of a problem. If your app depends on the network to run in debug mode, you can’t just switch a device into airplane mode to see how it reacts to an outage. Instead, you have to take a more precise approach to cutting your app off from the rest of the world. Enter Little Snitch.

Little Snitch, by Objective Development, is built to shine a light on the invisible network connections that your Mac makes on a daily basis. It tracks and displays them in a way that’s easy to see, understand, and change, and it comes with a really cool (and also slightly terrifying) map view that shows you every internet connection that every app on your Mac makes. If you ever want to see which analytics tools, CDNs, and bug trackers your favorite apps use, Little Snitch will tell you.

Today, though we’re going to be using it for a slightly off-label purpose: selectively severing network access for an app running in a simulator.

Step 1: Install Little Snitch

Grab a copy of Little Snitch and follow the installation instructions to start the network monitor on your Mac. It reaches pretty deep into the system to track any and all network connections, so you’ll need to type in your admin password a couple of times and (horror of horrors) restart your Mac before the network monitor can do its thing.

Step 2: Enable Silent Mode

Little Snitch can run in one of a few different modes: Alert, Silent Allow, or Silent Deny. We’re not trying to lock down network access to the host machine right now, so select Silent Allow when prompted. If you want to change the setting later, you can always do so from the menu bar.

Step 3: Hold Your Nose, and Launch the Network Monitor

This step will be mildly terrifying. Your Mac makes hundreds to thousands of internet connections every day, and you may not be aware of them all. You can use Little Snitch to lock these down if that’s your persuasion, but for our purposes right now, I just need you to launch the Network Monitor view and try not to dissolve into a puddle like I did when I first launched it.

Got it launched? Still sane? 🙌 Cool! So now, with your app running in a simulator, use the search field of the Network Monitor view to show only connections made by your app. Usually searching for something "simulator" will get you pretty close. From there, you can enable and disable individual network connections by just tapping on the ✓ and ✗ buttons.

Step 4: Experiment to Your ❤️’s Content

It’s a little thing, but having the ability to quickly and easily block my app’s connection to AWS S3 without rebuilding has been really handy on my most recent project. I also tried temporarily disabling my bug tracker connection to see how the app responds to offline crashes.

How do you sever network ties? Share your thoughts in the comments.