iOS Simulator
disable network
iOS development
network settings
app testing

How to turn off the network (airplane mode) in the iOS Simulator

Codemia Knowledge Hub ·

The iOS Simulator has no airplane mode toggle or network switch, because it shares the host Mac's network stack. To simulate being offline, disable networking on the Mac, use Network Link Conditioner to drop all traffic, or build a network abstraction into your app that test builds can switch to offline.

Why the Simulator has no airplane mode

On a physical device, airplane mode is a hardware-level toggle for the cellular radio, Wi-Fi chip and Bluetooth. The Simulator is a user-space macOS process that does not emulate network hardware. Every request from a simulated app goes through the Mac's own TCP/IP stack and interfaces, so you cannot disable networking for the Simulator alone without affecting the whole Mac.

Turning off the Mac's Wi-Fi

This is the most direct option, and it takes the entire machine offline. From the menu bar, click the Wi-Fi icon and choose "Turn Wi-Fi Off" (unplug the cable if you are on Ethernet). From the command line:

bash
1# Turn off Wi-Fi (en0 is the default Wi-Fi interface)
2networksetup -setairportpower en0 off
3
4# Turn it back on
5networksetup -setairportpower en0 on
6
7# List all network interfaces to find the right one
8networksetup -listallhardwareports

A script can wrap the cycle so networking is restored when you finish:

bash
1#!/bin/bash
2# offline-test.sh - Run a test session with networking disabled
3
4INTERFACE="en0"
5
6echo "Disabling Wi-Fi..."
7networksetup -setairportpower "$INTERFACE" off
8
9echo "Network is off. Run your Simulator tests now."
10echo "Press Enter to restore networking."
11read -r
12
13networksetup -setairportpower "$INTERFACE" on
14echo "Wi-Fi restored."

The cost is that the Mac loses internet access for the duration: IDE features, package managers, documentation lookup and other network tools stop working.

Network Link Conditioner (NLC) is an Apple developer tool that applies latency, bandwidth limits and packet loss to network traffic. It cannot switch the network off outright, but it can degrade it until it behaves like being offline.

Installing it

NLC ships in the "Additional Tools for Xcode" package:

  1. Open Xcode > Settings > Components.
  2. Or download from developer.apple.com/download/more and search "Additional Tools."
  3. Install the Network Link Conditioner preference pane from the downloaded DMG.

It then appears in System Settings > Network Link Conditioner.

Creating a 100% packet loss profile

  1. Open Network Link Conditioner in System Settings.
  2. Click "Manage Profiles" then click the "+" button.
  3. Configure the profile:
ParameterDownlinkUplink
Bandwidth0 kbps0 kbps
Packets Dropped100%100%
Delay0 ms0 ms
  1. Name it "100% Packet Loss" and save.
  2. Select the profile and toggle NLC on.

With the profile active, every request from the Simulator (and the Mac) times out. Connections are attempted but every packet is dropped, so your app sees the same timeouts and network errors as a real offline device.

From the command line

NLC itself is built on the dnctl/pf dummynet packet shaper, which you can drive directly:

bash
1# Drop 100% of outgoing packets (plr 1 = 100% loss; bw 0 would mean unlimited)
2sudo dnctl pipe 1 config plr 1
3echo "dummynet out all pipe 1" | sudo pfctl -f -
4sudo pfctl -E
5
6# Restore normal networking
7sudo pfctl -f /etc/pf.conf
8sudo dnctl -q flush

Stubbing requests inside the app with URLProtocol

The most precise approach leaves the system network alone and injects an offline network layer into your app during testing. A custom URLProtocol subclass can intercept every request and fail it:

swift
1class OfflineURLProtocol: URLProtocol {
2    override class func canInit(with request: URLRequest) -> Bool {
3        return true  // Intercept all requests
4    }
5
6    override class func canonicalRequest(for request: URLRequest) -> URLRequest {
7        return request
8    }
9
10    override func startLoading() {
11        let error = NSError(
12            domain: NSURLErrorDomain,
13            code: NSURLErrorNotConnectedToInternet,
14            userInfo: [NSLocalizedDescriptionKey: "Simulated offline"]
15        )
16        client?.urlProtocol(self, didFailWithError: error)
17    }
18
19    override func stopLoading() {}
20}
21
22// Register in your test setup
23URLProtocol.registerClass(OfflineURLProtocol.self)

Toggling it with a launch argument

swift
1// In AppDelegate or your networking layer
2if ProcessInfo.processInfo.arguments.contains("--offline") {
3    URLProtocol.registerClass(OfflineURLProtocol.self)
4}

Pass the argument in your Xcode scheme under "Arguments Passed On Launch", or from UI tests:

swift
let app = XCUIApplication()
app.launchArguments.append("--offline")
app.launch()

This is the only approach that affects the Simulator alone without disrupting the Mac's connectivity.

Blocking traffic through a proxy

Charles Proxy or mitmproxy can intercept Simulator traffic and block requests selectively:

bash
1# Using mitmproxy to block all traffic (444 closes the connection without a response)
2mitmproxy --mode regular --set block_list='/~all/444'
3
4# Or use Charles Proxy's Throttle Settings
5# Enable Throttling > select "No network" preset

The Simulator inherits the Mac's proxy settings, so set the HTTP proxy in System Settings > Wi-Fi > Advanced > Proxies on the Mac.

Comparing the options

MethodScopeSimulator-onlyPrecisionSetup effort
Disable Mac Wi-FiSystem-wideNoBinary on/offNone
Network Link ConditionerSystem-wideNoConfigurable (latency, loss, bandwidth)Low
URLProtocol stubbingApp-levelYesFull control per requestMedium
Proxy (Charles/mitmproxy)System-wide or app-scopedPartially (via proxy config)Per-request blockingMedium
NWPathMonitor overrideApp-levelYesStatus reporting onlyLow

Testing transitions between online and offline

Real users move in and out of connectivity, so test the transitions as well as the offline state:

swift
1import Combine
2import Network
3
4class NetworkMonitorWrapper: ObservableObject {
5    private let monitor = NWPathMonitor()
6    @Published var isConnected = true
7
8    init() {
9        monitor.pathUpdateHandler = { [weak self] path in
10            DispatchQueue.main.async {
11                self?.isConnected = (path.status == .satisfied)
12            }
13        }
14        monitor.start(queue: DispatchQueue.global())
15    }
16}

Toggle Network Link Conditioner on and off during a running session, and the NWPathMonitor callbacks fire as they would on a real device.

Offline testing gotchas

NWPathMonitor reports the Mac's state. If you disable Mac Wi-Fi, the monitor correctly reports .unsatisfied, but you cannot make it report offline while the Mac is online, short of the URLProtocol approach.

Testing only the offline state. Check that the app recovers when connectivity returns: pending requests retry, cached data refreshes and the UI leaves its error state.

Reachability libraries that only check interfaces. Many legacy Reachability wrappers check whether an interface is available, not whether a host is reachable. In the Simulator the interface stays "available" even when NLC drops every packet, so test with real HTTP requests.

Leaving Network Link Conditioner on. NLC persists across reboots, and a forgotten "100% Packet Loss" profile breaks all networking on your Mac. Add a reminder, or use the command-line approach, which resets on reboot.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms