spe*_*ing 13 vpn frameworks objective-c ios8
Apple在iOS 8上发布了一个新的框架"NetworkExtension".
我想用NEVPNManager从应用程序启动VPN连接,还是让这个框架再次使用?
有关于此框架的某些信息或示例吗?我无法在developer.apple.com网站上找到有关它的信息,只能在头文件中找到.
谢谢
代码看起来像这样(确切的实现取决于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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5874 次 |
| 最近记录: |