I've implemented a VPN app for macOS with Packet Tunnel Provider.
I've configured it to be onDemand, which should always connect:
targetManager?.isOnDemandEnabled = true
let onDemandRuleConnect = NEOnDemandRuleConnect()
targetManager?.onDemandRules = [onDemandRuleConnect
I've also set it to disconnect on sleep:
targetManager?.protocolConfiguration?.disconnectOnSleep = true
The question:
From the logs I have I see that the Mac enters sleep mode, so stopTunnelWithReason is called with reason 15 (The device went to sleep and disconnect).
Right after that, the VPN status changed to 'Disconnected' (as expected),
but then, right after that, the VPN status changed to 'Connecting' - this is probably because of how I set the onDemand, but I'm not sure of it - if the device enters sleep, why does the system starts the VPN again?
I think this behavior is causing me some problems.
What's the best way to "fix" this?