Getting Permission Denied error on manager loadFromPreferencesWithCompletionHandler
Asked Answered
E

3

9

In my app I am trying to configure VPN settings in App load delegate. I am calling following method in my app delegate

- (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");
                    }
                }
            }];
        }
    }];
}

but I am getting error on manager loadFromPreferencesWithCompletionHandler

Error: Failed to load the configuration: Error Domain=NEVPNErrorDomain Code=5 "permission denied" UserInfo={NSLocalizedDescription=permission denied}

I thought it was because of missing capabilities but Personal VPN is enabled in capabilities.

Erlking answered 11/1, 2017 at 16:34 Comment(1)
is your problem solved ?Nightwalker
A
17

Go to Xcode -> Project -> Targets -> Capabilities and Enable VPN and Enable Network Extensions. enter image description here

Admissible answered 30/5, 2018 at 6:28 Comment(1)
how to do that in xcode 13?Questionnaire
C
0

To fix the issue, go to Xcode > Project > capabilities and enable personal VPN.

Clarinda answered 9/8, 2017 at 7:10 Comment(0)
H
0
  1. In my case, I had added the Capabilities correctly, but an error is still reported

  2. when I restart my iPhone , then run the project, every thing work fine

Hudis answered 16/4, 2021 at 5:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.