I am developing a macOS app and want to check connectivity status. I’ve created a simple connectivity observer using NWPathMonitor; I use it as en environment object:
@Observable
class ConnectivityMonitor {
private let queue = DispatchQueue(label: "ConnectivityMonitorQueue")
private let monitor = NWPathMonitor()
private(set) var isConnected: Bool = false
init() {
monitor.pathUpdateHandler = { [weak self] path in
DispatchQueue.main.async {
self?.isConnected = path.status == .satisfied
print("network path changed: ", path.status)
}
}
monitor.start(queue: queue)
}
}
To check different connectivity statuses, I use Network Link Conditioner prefpane (I will call it NLC) provided with Xcode Additional Tools by Apple.
I don’t know why but NWPathMonitor does not respond to NLC profile changes.
For example; I set NLC profile to 100% Loss which means there is no internet connection on the network at all. But NWPathMonitor’s pathUpdateHandler
is not called.
Do I miss something? Thank you.