NWPathMonitor mocking for Simulator using Network Extension

Is it possible to mock the behavior of NWPathMonitor for a specific app?

The scenario I want to support I've created an app called RocketSim, a developer tool for Xcode's Simulator. I've already created Airplane mode, which disables networking calls from URLSession from a specific bundle identifier app installed on the Simulator.

Now, I want to support blocking NWPathMonitor as well. I believe the Simulator uses macOS's NWPathMonitor and does not use any specific HTTP request or similar to determine the reachability state.

Is there a way I can make NWPathMonitor return unsatisfied when my 'airplane mode' is turned on? Potentially using a Network Extension?

Is there a way I can make NWPathMonitor return unsatisfied when my 'airplane mode' is turned on?

Not in any supported way.

In general, the simulator uses the host Mac’s networking stack. Thus, I’d expect NWPathMonitor to reflect the Mac’s networking state. And, indeed, that’s what I see when I tested it here in my office.

There isn’t any supported way to change that relationship. You could try hacking something together with NE, but I’m sceptical that it’ll actually work and, even if it does, I’m more sceptical about its long-term sustainability.

The correct way to support this would be via a new simctl option, and I recommend that you file an enhancement request for that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

NWPathMonitor mocking for Simulator using Network Extension
 
 
Q