NEVPNManager - onDemand after restarting the device - are rules still applies?

A question regarding NEVPNManager onDemand -

For my VPN app (Packet Tunnel Provider), let's say I configured the VPN with onDemand and some rules, connected to the VPN, and then I restarted the device. What should happen after the restart? Is the VPN suppose to connect again according to the rules? Or am I have to open the VPN app and press the connect button again?


I know that for alwaysOn the VPN should be activated after restarting the device, but I don't know about onDemand.

Accepted Reply

Is the VPN suppose to connect again according to the rules?


The VPN connection should start or stop based the criteria setup for the application. For example if using a specific network path, i.e., WiFi or Cellular or possibly connecting to a service are a few examples of criteria to start an onDemand connection. On a side note, I have seen instances where the request needs to actually be made for a service before the connection kicks on, if we were talking about HTTPS as the service that kicks on the VPN connection.

Replies

Is the VPN suppose to connect again according to the rules?


The VPN connection should start or stop based the criteria setup for the application. For example if using a specific network path, i.e., WiFi or Cellular or possibly connecting to a service are a few examples of criteria to start an onDemand connection. On a side note, I have seen instances where the request needs to actually be made for a service before the connection kicks on, if we were talking about HTTPS as the service that kicks on the VPN connection.

"connection should start or stop based the criteria setup for the application" - correct, but will it happen also after restarting the device?

| correct, but will it happen also after restarting the device?


It's hard to give an exact answer on that because the onDemand VPN criteria might not be met after restart. The best way to test this is to meet your criteria for the onDemand VPN once the device has been restarted. For example, configure the VPN to connect on demand once the device in on Wi-Fi and after restart make sure you are within range of the Wi-Fi to test this activity.

Thanks for the suggestion, this is exactly what I tried to do and I saw that even it was supposed to connect - it didn't.
So I'm not sure if this is the desired behavior, and those rules aren't applied after restarting the device, or the second option - a bug somewhere at my code (or even a bug at iOS/macOS)

No problem, happy to help. Out of curiosity, when the device restarts and is configured to kick on the VPN within Wi-Fi range, does the VPN kick on if you then open Safari and initiate a network request?


Also, when the device is restarted within Wi-Fi range, what shows up under Settings -> VPN -> Your VPN? Does your VPN display as active?

Sry for the long delay. I checked this at another device (not the device I'm developing on) and it worked well - after restarting the iPhone, the VPN connected automatically. I didn't test it on macOS yet.

Thanks for the help!