获取权限拒绝管理器loadFromPreferencesWithCompletionHandler上的错误

时间:2017-01-11 16:34:54

标签: ios objective-c xcode vpn

在我的应用中,我正在尝试在App load委托中配置VPN设置。我在我的app delegate中调用了以下方法

$rules = ['first_name' => '...', 'last_name' => '...', 'dob' => '...'];
$data = $this->validate($request, $rules);

Customer::create($data); // $data contains only first_name, last_name and dob

但我在- (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}

3 个答案:

答案 0 :(得分:3)

转到 Xcode - >项目 - >目标 - >能力和 启用VPN并启用网络扩展。 enter image description here

答案 1 :(得分:0)

要解决此问题,请转到Xcode>项目>功能和启用个人VPN。

答案 2 :(得分:0)

  1. 就我而言,我有 added the Capabilities correctly,但仍然报告错误

  2. 当我 restart my iPhone 运行项目时,一切正常