I've noticed that if a call to startVPNTunnel() is made while no network interface is active on the system, the call "succeeds" (i.e., doesn't throw), but the VPN connection state goes straight from NEVPNStatus.disconnecting to NEVPNStatus.disconnected.
The docs for startVPNTunnel() state:
In Swift, this method returns Void and is marked with the throws keyword to indicate that it throws an error in cases of failure.
Additionally, there is an NEVPNConnectionError enum that contains a noNetworkAvailable case. However, this isn't thrown in this case, when startVPNTunnel() is called.
I just wanted to ask under what circumstances startVPNTunnel() does throw, and should this be one of them?
Additionally, to catch such errors, would it be better to call fetchLastDisconnectError() in the .NEVPNStatusDidChange handler?
However, this isn't thrown in this
That doesn’t strike me as strange. We generally don’t document the timing and specific errors thrown for particular user scenarios, and that’s not an accidental omission. Leaving these as implementation details gives us more flexibility to evolve the system.
I recommend that you write your code to handle both sources of errors.
Additionally, to catch such errors, would it be better to …?
Yes, but I wouldn’t phrase it like that. Rather, I’d say that your app should be prepared to handle errors from both:
- The start method throwing, and
- The status changing to
.disconnected
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"