NEVPNManager instance is showing nil

417 views Asked by At

I had created network manager by using the below code. but as soon the first line of call is run the manager is being nil so any other methods are getting not effected. Can Anyone let me know that what wrong thing I had done ?

        NEVPNManager *manager = [NEVPNManager sharedManager];

        NEVPNProtocolIPSec *p = [[NEVPNProtocolIPSec alloc] init];
        p.username = @"MYUSERNAME";
        p.passwordReference = [@"MYPW" dataUsingEncoding:NSUTF8StringEncoding];
        p.serverAddress = @"[NetworkIP]";
        p.authenticationMethod = NEVPNIKEAuthenticationMethodSharedSecret;
        p.sharedSecretReference = [@"SharedSecretHashCode"  dataUsingEncoding:NSUTF8StringEncoding];

        [manager setProtocol:p];
        [manager setOnDemandEnabled:NO];
        [manager setLocalizedDescription:@"VIT VPN"];
         NSArray *array = [NSArray new];
        [manager setOnDemandRules: array];
         NSLog(@"Connection desciption: %@", manager.localizedDescription);
         NSLog(@"VPN status:  %li", (long)manager.connection.status);


         [manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
            if(error) {
                NSLog(@"Save error: %@", error);
            }
         }];

"manager" is being nil . please help. thanks in advance.

1

There are 1 answers

4
Esha On

I found Solution for my question for the NEVPNManager instances.

When using this to the app developer must need its related certificates in which The APPID has has enabled the VPN Configuration & controls. and this app must need to run in the device.

enter image description here

So the NEVPNManager will not be nil and it can be adapt from the shared instance of the device. (also this is from NetworkExtension.framework which is available for iOS8 & higher devices)

May be this can help anyone who is having the same issue.