– (IBAction)pressBtn:(UIButton *)sender {
switch (sender.tag)
{
case 0://创建VPN描述文件
{
[[NEVPNManager sharedManager] loadFromPreferencesWithCompletionHandler:^(NSError *error){
if(error)
{
NSLog(@”加载偏好设置失败! Load error: %@”, error);
}
else
{
//配置IPSec
[self setupIPSec];
//保存VPN到系统->通用->VPN->个人VPN
[[NEVPNManager sharedManager] saveToPreferencesWithCompletionHandler:^(NSError *error){
if(error)
{
ALERT(@”保存VPN配置信息失败”, error.description);
NSLog(@”保存VPN配置信息失败!Save error: %@”, error);
}
else
{
NSLog(@”Saved!”);
ALERT(@”Saved”, @”保存VPN配置信息 Success!”);
}
}];
}
}];
break;
}
case 3://TODO:断开VPN
{
[[NEVPNManager sharedManager] loadFromPreferencesWithCompletionHandler:^(NSError *error){
if (!error)
{
[[NEVPNManager sharedManager].connection stopVPNTunnel];
}else{
NSLog(@”加载偏好设置失败! Load error: %@”, error);
}
}];
break;
}
case 2://TODO:连接VPN(前提是必须有描述文件)
{
[[NEVPNManager sharedManager] loadFromPreferencesWithCompletionHandler:^(NSError *error){
if (!error)
{
//配置IPSec
[self setupIPSec];
[[NEVPNManager sharedManager].connection startVPNTunnelAndReturnError:&error];
}else{
NSLog(@”加载偏好设置失败! Load error: %@”, error);
}
}];
break;
}
default:
break;
}
}
switch (sender.tag)
{
case 0://创建VPN描述文件
{
[[NEVPNManager sharedManager] loadFromPreferencesWithCompletionHandler:^(NSError *error){
if(error)
{
NSLog(@”加载偏好设置失败! Load error: %@”, error);
}
else
{
//配置IPSec
[self setupIPSec];
//保存VPN到系统->通用->VPN->个人VPN
[[NEVPNManager sharedManager] saveToPreferencesWithCompletionHandler:^(NSError *error){
if(error)
{
ALERT(@”保存VPN配置信息失败”, error.description);
NSLog(@”保存VPN配置信息失败!Save error: %@”, error);
}
else
{
NSLog(@”Saved!”);
ALERT(@”Saved”, @”保存VPN配置信息 Success!”);
}
}];
}
}];
break;
}
case 3://TODO:断开VPN
{
[[NEVPNManager sharedManager] loadFromPreferencesWithCompletionHandler:^(NSError *error){
if (!error)
{
[[NEVPNManager sharedManager].connection stopVPNTunnel];
}else{
NSLog(@”加载偏好设置失败! Load error: %@”, error);
}
}];
break;
}
case 2://TODO:连接VPN(前提是必须有描述文件)
{
[[NEVPNManager sharedManager] loadFromPreferencesWithCompletionHandler:^(NSError *error){
if (!error)
{
//配置IPSec
[self setupIPSec];
[[NEVPNManager sharedManager].connection startVPNTunnelAndReturnError:&error];
}else{
NSLog(@”加载偏好设置失败! Load error: %@”, error);
}
}];
break;
}
default:
break;
}
}
解决方案:100分
初始btn.seletced = NO;
点击事件
if(!btw.seletecd)
{
//配置文件 链接
}
else
{
//断开链接
}
btn.seletced = !btn.seletced;
点击事件
if(!btw.seletecd)
{
//配置文件 链接
}
else
{
//断开链接
}
btn.seletced = !btn.seletced;