NETunnelProviderManager -loadAllFromPreferences returns an empty manager

hi eskimo:

I have encountered -loadAllFromPreferencesWithCompletionHandler failed to load the already configured VPN, the following is the method I use:


create:

- (NETunnelProviderManager *)createProviderManager {


NETunnelProviderManager *manager = [[NETunnelProviderManager alloc] init];

NETunnelProviderProtocol *conf = [[NETunnelProviderProtocol alloc] init];

conf.serverAddress = @"123.321.123.123";

manager.protocolConfiguration = conf;

manager.localizedDescription = @"xVPN";


return manager;

}

save:

- (void)saveConfigWithManger:(NETunnelProviderManager *)manager parameters:(NSDictionary *)parameters Complete:(void(^)(void))complete {

NSString *ip = parameters[@"ip"];//ip

NSString *port = parameters[@"port"];//port


if (!ip || !port) {

return;

}

NSArray<Router *> *routers = parameters[@"routers"];

BOOL isOverseas = [parameters[@"isOverseas"] boolValue];


NSString *configurationFileURL = [[NSBundle mainBundle] pathForResource:@"client" ofType:@"config"];

NSString *config = [NSString stringWithContentsOfFile:configurationFileURL encoding:NSUTF8StringEncoding error:nil];

config = [config stringByReplacingOccurrencesOfString:@"addrIP" withString:ip];

config = [config stringByReplacingOccurrencesOfString:@"portID" withString:port];

NETunnelProviderProtocol *tunnelProtocol = (NETunnelProviderProtocol *)manager.protocolConfiguration;

NSMutableDictionary *providerConfiguration = [NSMutableDictionary dictionary];

providerConfiguration[@"config"] = [config dataUsingEncoding:NSUTF8StringEncoding];

providerConfiguration[@"authUser"] = [[NSUserDefaults standardUserDefaults] stringForKey:@"kAuthorization"];


tunnelProtocol.serverAddress = @"123.321.123.123";


providerConfiguration[@"routers"] = routes;

providerConfiguration[@"nodeIP"] = ip;


providerConfiguration[@"isOverseas"] = isOverseas ? @"1" : @"0";//


tunnelProtocol.providerConfiguration = providerConfiguration;

manager.protocolConfiguration = tunnelProtocol;

// __weak typeof(self) weakSelf = self;

[manager saveToPreferencesWithCompletionHandler:^(NSError * _Nullable error) {


if (!error) {

NSLog(error);

}


}];

}


load:

[NETunnelProviderManager loadAllFromPreferencesWithCompletionHandler:^(NSArray<NETunnelProviderManager *> * _Nullable managers, NSError * _Nullable error) {

NETunnelProviderManager *manager = nil;

if (managers.count > 0) {

manager = managers.firstObject;

NSLog(@"manager loaded:%@", manager);

} else {

manager = [self createProviderManager];

NSLog(@"create new manager:%@", manager);

}

manager.enabled = YES;

complete(manager);

}];


My use scenario is to kill the APP process after connecting to the VPN, and then restart the APP. In most cases, it can be loaded into the manage(log in consol manager loaded:). Occasionally, the load cannot be loaded(log in consol: create new manager:). As a result, I cannot obtain the VPN status after starting the APP.


How can I solve this problem?

Replies

Occasionally, the load cannot be loaded (log in console: create new manager:).

In that case is

error
set?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I see this same issue. Occassionally the managers.count is 0 eventhough the manager is installed and working properly. In my case the error is not set.

the error is not set

the error is not set

Hmmm. Alas, I’ve no explanation for that. If you can reproduce it reasonably reliably, I recommend that you file a bug about this. It’d be best if you included a small test project that reproduces the problem, an explanation of how you reproduced it, and a sysdiagnose log taken shortly after reproducing it [1].

Please post your bug number, just for the record.

Beyond that, if this problem is causing you a lot of grief then you can open a DTS tech support incident and I’ll see if I can find a workaround.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] See the instructions on our Bug Reporting > Profiles and Logs page.