在我的应用程序中,我试图在应用程序负载委托中配置VPN设置。我在我的应用程序委托中调用以下方法
- (void)configureVPN { NEVPNManager *manager = [NEVPNManager sharedManager]; [manager loadFromPreferencesWithCompletionHandler:^(NSError * _Nullable loadError) { if (loadError) { NSLog(@"vpn setup error: %@", loadError); } else { [manager setOnDemandEnabled: YES]; NSMutableArray *rules = [[NSMutableArray alloc] init]; NEOnDemandRuleConnect *connectRule = [NEOnDemandRuleConnect new]; [rules addObject:connectRule]; [manager setOnDemandRules:rules]; [manager saveToPreferencesWithCompletionHandler:^(NSError * _Nullable saveError) { if (saveError) { NSLog(@"vpn setup error: %@", saveError); } else { NSLog(@"vpn config set"); NSError *connError; [manager.connection startVPNTunnelAndReturnError:&connError]; if (connError) { NSLog(@"Unable to connect to VPN: %@", connError); } else { NSLog(@"VPN connection established"); } } }]; } }]; }
但是我遇到了错误 manager loadFromPreferencesWithCompletionHandler
错误:
Failed to load the configuration: Error Domain=NEVPNErrorDomain Code=5 "permission denied" UserInfo={NSLocalizedDescription=permission denied}
我以为是因为缺少功能,但是Personal VPN
启用了功能。
转到Xcode->项目->目标->功能,然后启用VPN和启用网络扩展。