【发布时间】:2015-10-26 10:43:29
【问题描述】:
我正在使用下面的代码来配置 VPN
- (void)setupConfiguration
{
NEVPNManager *manager = [NEVPNManager sharedManager];
int status = manager.connection.status;
if (status == NEVPNStatusConnected) {
[manager.connection stopVPNTunnel];
}
else
{
[manager loadFromPreferencesWithCompletionHandler:^(NSError *error)
{
if (error) {
NSLog(@"Load config failed [%@]", error.localizedDescription);
return;
}
NEVPNProtocolIPSec *p = (NEVPNProtocolIPSec *)manager.protocol;
if (!p) {
p = [[NEVPNProtocolIPSec alloc] init];
}
NSString *username = [Username];
NSString *url = @"Server URL";
p.username = username;
p.serverAddress = url;
p.passwordReference = [Password from Keychain];
p.authenticationMethod = NEVPNIKEAuthenticationMethodSharedSecret;
p.sharedSecretReference = [Shared secret from Keychain];
//p.localIdentifier = @"";
//p.remoteIdentifier = @"";
p.disconnectOnSleep = NO;
p.useExtendedAuthentication = YES;
[manager setProtocol:p];
[manager setOnDemandEnabled:NO];
[manager setLocalizedDescription:@"VIT VPN"];
NSLog(@"Connection desciption: %@", manager.localizedDescription);
NSLog(@"VPN status: %li", (long)manager.connection.status);
[manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
if(error) {
NSLog(@"Save error: %@", error);
} else {
NSLog(@"Saved!");
}
}];
}];
}
}
我在viewDidLoad 上调用此方法。
当用户在完成配置文件安装后从设备 VPN 设置导航到我们的应用程序时,我在日志中收到此错误 - "error in __connection_block_invoke_2: Connection interrupted"。之后,当我尝试连接到 VPN 服务器时,什么也没有发生。
谁能帮我解决这个问题,为什么我会收到这个错误?
注意:- 我已按照以下教程进行操作:
1.http://ramezanpour.net/post/2014/08/03/configure-and-manage-vpn-connections-programmatically-in-ios-8/
2. https://disqus.com/home/discussion/ramezanpour/configure_and_manage_vpn_connections_programmatically_in_ios_8/newest/
【问题讨论】:
标签: objective-c ios8 vpn