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]];
}
}
}];
}
}];