Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetworkExtension - NEVPNManager

Apple published with iOS 8 a new Framework "NetworkExtension".

I want to start a VPN Connection out of an app with the NEVPNManager, or has this Framework another use?

Has somebody information or an example about this Framework? I can´t find information about it on the developer.apple.com website, only in the header files.

Thanks

like image 623
speedboosting Avatar asked Jun 05 '14 09:06

speedboosting


1 Answers

The code would look something like this (exact implementation depends on the type of VPN):

NEVPNManager *manager = [NEVPNManager sharedManager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(vpnConnectionStatusChanged) name:NEVPNStatusDidChangeNotification object:nil];

NEVPNProtocolIPSec *protocol = [[NEVPNProtocolIPSec alloc] init];
protocol.username = @“[Your username]”;
protocol.passwordReference = [KeyChainAccess loadDataForServiceNamed:@“[Your Service Name]"];
protocol.serverAddress = @“[Your Server Address]“;
protocol.authenticationMethod = NEVPNIKEAuthenticationMethodCertificate;
protocol.localIdentifier = @“[Your Local identifier]”;
protocol.remoteIdentifier = @“[Your Remote identifier]”;
protocol.useExtendedAuthentication = NO;
protocol.identityData = [Your VPN certification private key];
protocol.disconnectOnSleep = NO;
[manager setProtocol:protocol];

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

[manager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
    // do config stuff
    [manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
    }];
}];


NSError *startError;
[[NEVPNManager sharedManager].connection startVPNTunnelAndReturnError:&startError];
if(startError) {
      NSLog(@"Start error: %@", startError.localizedDescription);
}
like image 133
mobileideafactory Avatar answered Nov 16 '22 18:11

mobileideafactory