IPSec VPN using NEVPNManager does not disconnect on sleep.

I'm working on an IPSec VPN solution for macOS. I've managed to get a VPN configuration installed via NEVPNManager and everything works. Except, my requirment is to disconnect the VPN when mac goes to sleep. Below is the IPSec profile which I am using.


- (void)setupIPSec

{

[self configVPNKeychain];

NSData *passwordData = [self persistentReferenceForSavedPassword:@"username" service:kPasswordReference account:@"account" description:@"login"];

NSData *sharedSecretData = [self persistentReferenceForSavedPassword:@"54343333" service:kSharedSecretReference account:@"account" description:@"IPSec Shared Secret"];

// config IPSec protocol

NEVPNProtocolIPSec *p = [[NEVPNProtocolIPSec alloc] init];

p.username = @"username012134";

p.serverAddress = @"ipsec.route.com";

// get password persistent reference from keychain

p.passwordReference = passwordData;

p.authenticationMethod = NEVPNIKEAuthenticationMethodSharedSecret;

p.sharedSecretReference = sharedSecretData;

p.useExtendedAuthentication = YES;

p.disconnectOnSleep = YES; // This is were I am setting YES to disconnect the VPN connection when on Sleep.

[NEVPNManager sharedManager].enabled = YES;

[NEVPNManager sharedManager].protocolConfiguration = p;

[NEVPNManager sharedManager].localizedDescription = @"VPN";

}


Can anyone please guide me.

Replies

In this instance how are you determining the VPN is staying connected? Are you able to see this at the server level once the machine goes to sleep? Also, for my own curiosity, are you trigger the sleep test by just letting your machine go to sleep or actually putting it to sleep via Apple -> Sleep?