【发布时间】:2017-06-25 11:07:46
【问题描述】:
我正在尝试将我的 VPN 配置保存到首选项中,该首选项已经有效(我能够连接到我的 VPN)。但是由于某种原因,每次我再次运行代码而不是使用最后一个配置时,它都会创建一个新配置。所以,我最终得到了一堆配置。
这是我当前的代码,如果有人可以让我知道它出了什么问题,那就太棒了。谢谢!
// Initialize Manager
NETunnelProviderManager *manager = [[NETunnelProviderManager alloc] init];
[manager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
if (error) {
NSLog(@"Load Error: %@", error.description);
} else {
// Create the protocol object
NETunnelProviderProtocol *protocol = [[NETunnelProviderProtocol alloc] init]; // Create the protocol object
// Configure the protocol object
protocol.providerBundleIdentifier = @"com.nfisc.testvpn.ptp"; // Bundle ID of tunnel provider
protocol.providerConfiguration = @{}; // Currently blank, but will be used later
protocol.serverAddress = @"0.0.0.0"; // Ommited for security reasons
protocol.username = @"username"; // The username for the configuration
protocol.identityDataPassword = @"password"; // The password for the configuration
protocol.disconnectOnSleep = NO;
// Configure the manager with the protocol
manager.protocolConfiguration = protocol;
manager.enabled = true;
[manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
if (error) {
NSLog(@"Save Error: %@", error.description);
} else {
if ([[manager connection] status] != NEVPNStatusConnected) {
NSLog(@"Starting VPN");
[self start:manager];
} else {
NSLog(@"VPN Already Connected");
[_statusLabel setText:@"Connected"];
[_statusLabel setTextColor:[UIColor greenColor]];
}
}
}];
}
}];
【问题讨论】:
标签: ios objective-c network-programming networkextension nevpnmanager