NWPathMonitor returns .unsatisfied the WiFi is back on simulator

I'm testing network loss handling in my app on the simulator.

  • Turning WiFi OFF triggers pathUpdateHandler with .unsatisfied status.
  • Turning WiFi back to ON triggers pathUpdateHandler with .unsatisfied status again.

I noticed that pathUpdateHandler is triggered right after I enabled WiFi, but before WiFi actually connects to the network. When the laptop is actually connected to the WiFi network - pathUpdateHandler isn't triggered, so my app stays in "offline" mode permanently.

networkMonitor.pathUpdateHandler = { [weak self] path in
    guard let self = self else { return }

    DispatchQueue.main.async {
        if path.status == .satisfied {
            self.status = .connected

        } else {
            print(path.unsatisfiedReason)
            self.status = .disconnected
        }
    }
}
monitor.start(queue: queue)

networkMonitor is retained by my DIContainer

Answered by DTS Engineer in 725750022

You should feel free to file a bug about this but the fundamental issue here is this:

I'm testing network loss handling in my app on the simulator.

Testing this sort of thing in the simulator is pointless; tests like this need to be run on a real device. The issue is that that simulator is using the macOS networking stack, and so it’s networking behaviour tracks macOS, not iOS.

ps If you do end up filing a bug, 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"

Accepted Answer

You should feel free to file a bug about this but the fundamental issue here is this:

I'm testing network loss handling in my app on the simulator.

Testing this sort of thing in the simulator is pointless; tests like this need to be run on a real device. The issue is that that simulator is using the macOS networking stack, and so it’s networking behaviour tracks macOS, not iOS.

ps If you do end up filing a bug, 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"

Hey guys, how's it going? I would like to know if someone filed a bug already. This is a problem at the project I'm working too! :(

I know that pathUpdateHandler is being called correctly for physical devices, but my team depends mostly on simulator for development, so we really need some consistent behavior for NWPathMonitor for our tests =/ @AlexeyRash, did you file a bug already? Could you send me the link for it?

Thanks :)

NWPathMonitor returns .unsatisfied the WiFi is back on simulator
 
 
Q