【问题标题】:NetworkExtension - NEVPNManager网络扩展 - NEVPNManager
【发布时间】:2014-07-26 05:01:00
【问题描述】:

Apple 在 iOS 8 中发布了一个新的框架“NetworkExtension”。

我想使用 NEVPNManager 从应用程序中启动 VPN 连接,或者此框架有其他用途吗?

有关于此框架的信息或示例吗? 我在 developer.apple.com 网站上找不到有关它的信息,只能在头文件中找到。

谢谢

【问题讨论】:

标签: objective-c frameworks vpn ios8


【解决方案1】:

代码如下所示(具体实现取决于 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);
}

【讨论】:

  • 如果您不是 MDM 供应商,是否可以使用它?
  • @Array 是的,您不需要 Apple 的任何初步批准,您只需像往常一样通过标准的应用程序批准流程。
  • 如何通过认证私钥数据?证书是否像捆绑包中一样添加到应用程序中?如果我们不设置identityData,每次连接vpn时都会提示输入密码吗?
猜你喜欢
  • 2019-04-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-02
  • 2018-12-24
  • 2021-08-22
  • 1970-01-01
  • 1970-01-01
  • 2010-09-18
相关资源
最近更新 更多