OSX 10.11中的NEVPNManager - 如何设置IKEV2 VPN连接

时间:2017-04-12 05:35:50

标签: ios objective-c macos vpn

我想创建(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
            }
        }];
    }
}];

奇怪的观察:

  • [NEVPNManager sharedManager]正在抓取其他mac app的配置(如果有的话);
  • 整个连接中没有来自mac的身份验证POPUP;
  • 相同的代码行在iOS中运行良好。

我在代码中做错了什么?

0 个答案:

没有答案