VPN-ikev2 - An Unexpected error occurred

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 = @"***";

NSString *pass = @"***";

[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);

}

}

Replies

It’s hard to say what’s going wrong based on the code you’ve posted. The majority of problems like this are caused by folks not setting up the

protocol.passwordReference
property correctly. You should take a look at the code I posted in this thread. If that doesn’t help my recommendation is that you open a DTS tech support incident and I can take look at your code in detail.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hello can you please send me a sample code on my email ?

Hello can you please send me a sample code on my email ?

The code I refer to was posted to DevForums in this thread. If you need more help than that, my recommendation is that you open a DTS tech support incident and I can assist you one-on-one.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hello,


i used your code to store passowrd in keychain but same Unexpected error while connecting,


i have installed .crt certificate in my device to connect with Profile (Created with Apple configure2)


same installed .crt certificate will work with Personal VPN Profile (Created by Code) ? or do i need to provide it via Identity data ?

i have installed .crt certificate in my device …

Is this a custom root certificate? Or a client certificate (actually not a certificate but a digital identity)? The former will have a payload type of

com.apple.security.root
and the latter a payload type of
com.apple.security.pkcs12
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"