I have a VPN app that is very sensitive to networking changes and so I have to refresh things every time the interface changes (like WiFi to LTE, LTE to WiFi, WiFi to wired, etc).
So I rely on NWPathMonitor to tell me about interface changes. Problem is, it's not so accurate all the time.
When I test it on my devices, everything works perfectly. For example, I turn off WiFi on my device, it runs pathUpdateHandler block and I can read the new preferred interface (availableInterfaces.first on the NWPath object). The name of the interface changes from en0
to pdp_ip0
. Or maybe there's no available interfaces now cause it doesn't have a data plan on the device. That's all good. I can have my VPN respond appropriately.
But I have one end user (likely more out there) where the NWPath interfaces aren't changing in the pathUpdateHandler block. This user gave me their sysdiagnose logs where I had the VPN printing out the availableInterfaces so I could see for myself. Sure enough, as they join a WiFi network, the preferred interface is still pdp_ip0
. isExpensive
is still true, even though they are using WiFi now. Then, when they leave the range of the WiFi, the preferred interface stays pdp_ip0
and that's when the VPN breaks for this because it's not being treated like a network change.
In the case of this user, they are joining a school wifi where they use their school login credentials to use the network. They are logging in each time successfully and using the WiFi. Also, the end user's device is on AT&T. These are two conditions I can't test myself.
I can't have it respond to every pathUpdateHandler
block run, because it runs quite a lot even when there's no network changes. When I tried this, it destabilized the VPN. So that's out. I just need a way to know when the network is changing and only have the VPN respond to the change at that time.
So, my question-- is there a reliable way to know this?