5 Replies
      Latest reply on Aug 13, 2018 1:13 AM by eskimo
      Vishal_sagar Level 1 Level 1 (0 points)

        Hello,

         

        i am creating ikev2 VPN profile by code, below is my code ,

         

        - i can connect to my VPN with manual configuration and also by installing profile (created with Apple Configure 2)

        but when i tried with this code ,it says "An Unexpected error occurred"

        -its not displaying any error code.

         

        Can anybudy please help me.

         

            [_vpnManager loadFromPreferencesWithCompletionHandler:^(NSError *error) {

           

                NEVPNProtocolIKEv2 *protocol = [[NEVPNProtocolIKEv2 alloc] init];

           

                protocol.serverAddress = @"severaddress";

                protocol.remoteIdentifier = @"serveraddress";

                protocol.localIdentifier = @"xxxx";

           

                protocol.authenticationMethod = NEVPNIKEAuthenticationMethodNone;

                protocol.useExtendedAuthentication = YES;

         

                protocol.username = @"xxx";

                NSString *pass = @"xxx";

                [self createKeychainValue:pass forIdentifier:@"VPN_PASSWORD"];

                protocol.passwordReference = [self searchKeychainCopyMatching:@"VPN_PASSWORD"];

         

                [_vpnManager setProtocolConfiguration:protocol];   

                [_vpnManager setEnabled:YES];

           

                [_vpnManager saveToPreferencesWithCompletionHandler:^(NSError *error){

                    if (error) {

                        NSLog(@"Save Error: %@",error);

                    }else{

                        NSLog(@"Saved");

                    

                        UIAlertView *alrt  =[[UIAlertView alloc] initWithTitle:@"" message:@"Profile Saved" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

                        [alrt show];

                        [self do_connect];

                    }

                }];

            }];

         

         

        - (Vois)do_connect{

         

                NSError *startError;

              

                [_vpnManager.connection startVPNTunnelAndReturnError:&startError];

                if (startError) {

                    NSLog(@"Start VPN failed: [%@]", startError.localizedDescription);

                }

        }