Search code examples
iosios8callbacknevpnmanager

NEVPNManager on-demand callbacks


I have a question about

loadPreferencesWithCompletitionHandler

And

savePreferencesWithCompletitionHandler of NEVPNManager.

Does blocks of this functions invoked when, for example, on-demand connection establishing ?

If yes, then does it triggers app to become active ?

If no, then what can I do if I need some preparations to do before VPN connection ?

Can I setup some sort of callback before connection ?


Solution

  • Nope. You are misunderstanding purpose of this blocks.

    They are called, when appropriate action (load or save vpn configuration) is completed and provide you NSError object, to help understand, if operation was successful.

    As far, as I found from official docs and experiments - there is no official way to achieve, what you want to do (setup callback before connection).

    However, you can subscribe to NEVPNStatusDidChangeNotification notification and check connection status through NEVPNManager, while your app is active:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeVpnStatus) name:NEVPNStatusDidChangeNotification object:nil];
    

    and didChangeVpnStatus method:

    NEVPNManager * vpnManager = [NEVPNManager sharedManager];
    switch (vpnManager.connectionStatus) {
        case NEVPNStatusInvalid:
            break;
        case NEVPNStatusDisconnected:
            break;
        case NEVPNStatusConnecting:
            break;
        case NEVPNStatusConnected:
            break;
        case NEVPNStatusReasserting:
            break;
        case NEVPNStatusDisconnecting:
            break;
    }