我想创建(Xcode 8.2,OSX 10.11)与NEVPNManager的IKEV2 VPN连接。
// setup protocol
NEVPNProtocolIKEv2 *p = [[NEVPNProtocolIKEv2 alloc] init];
p.serverAddress = vpnServer.address;
p.remoteIdentifier = vpnServer.address;
p.useExtendedAuthentication = NO;
p.disconnectOnSleep = NO;
p.authenticationMethod = NEVPNIKEAuthenticationMethodSharedSecret;
p.sharedSecretReference = [SHARED_SECRET_REF];
NEVPNManager *manager = [NEVPNManager sharedManager];
[manager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
if(error) {
// post error notification
} else {
manager.enabled = YES;
[manager setProtocolConfiguration:p];
[manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
if(error) {
// post error notification
}
else {
NEVPNManager *manager = [NEVPNManager sharedManager];
NSError *startError;
[manager.connection startVPNTunnelAndReturnError:&startError];
// Error Handling
}
}];
}
}];
奇怪的观察:
我在代码中做错了什么?