While implementing a VPN using the Packet Tunnel Network Extension framework I've stumbled upon different problems I cannot see well documented.
I am monitoring the changes in the interface and its status observing defaultPath. How should I react to the interface changes.
- Should I reset my tunnel when I go from WiFi to Cellular? Or should I reconnect it? I want to guarantee that when I perform an interface change my Internet traffic goes out using the tunnel interface.
- What should I do when the status changes in NWPathStatus changes? I am having trouble when my status changes from WiFi (satisfied) to WiFi (satisfied). The VPN is still up but the outgoing traffic doesn't use the tunnel interface. I don't want to cancelTunnelWithError(_:) every time I see an interface change. While this solves the problem and forces the traffic to go out using the tunnel interface as it's reestablishing the tunnel again and again it drains the battery and it's not the correct approach. Specially when at home there are constant WiFi (satisfied) to WiFi (satisfied) network changes that I don't wrap my head around what they can mean.
- How should I manage these changes when the device goes to and from sleep? There's a property, reasserting that specifies when the tunnel starts to reconnect, should I modify it when the device goes to sleep or when it wakes? And should I cancel or reconnect the tunnel when the device comes from sleep?
I haven't found much information on this so if someone could guide me a bit on how to solve this it'd be great.