ss-abramchuk / OpenVPNAdapter

Objective-C wrapper for OpenVPN library. Compatible with iOS and macOS.
GNU Affero General Public License v3.0
473 stars 209 forks source link

vpnAdapter disconnect received error #187

Closed jialovegirl closed 3 years ago

jialovegirl commented 3 years ago

I started the VPN through the app, and I encountered an error when closing the VPN connection on the iOS system settings page. Error Domain=me.ss-abramchuk.openvpn-adapter.error-domain Code=20 "Failed to reset tunnel. Check underlying error for more details." UserInfo={me.ss-abramchuk.openvpn-adapter.error-key.fatal=true, NSLocalizedDescription=Failed to reset tunnel. Check underlying error for more details., NSUnderlyingError=0x102b09750 {Error Domain=NEAgentErrorDomain Code=1 "(null)"}}

Then I want the VPN to be started only in the App and not on the system settings page. Is there a good way? thx!

`

- (void)startTunnelWithOptions:(NSDictionary *)options completionHandler:(void (^)(NSError *))completionHandler {
// Add code here to start the process of connecting the tunnel.
NETunnelProviderProtocol *protocolConfiguration = (NETunnelProviderProtocol *) self.protocolConfiguration;

NSDictionary *providerConfiguration = protocolConfiguration.providerConfiguration;

NSData *ovpnFileContent = [providerConfiguration objectForKey:@"ovpn"];
OpenVPNConfiguration *configuration = [[OpenVPNConfiguration alloc] init];
configuration.fileContent = ovpnFileContent;

NSError *error = nil;
_evaluation = [self.vpnAdapter applyConfiguration:configuration error:&error];

if(error) {
    completionHandler(error);
    return;
}

_vpnReachability = [[OpenVPNReachability alloc] init];
[_vpnReachability startTrackingWithCallback:^(OpenVPNReachabilityStatus status) {
    if(status == OpenVPNReachabilityStatusReachableViaWiFi) {
        [self.vpnAdapter reconnectAfterTimeInterval:5];
    } else return;
}];

_startHandler = completionHandler;
[self.vpnAdapter connectUsingPacketFlow:self.packetFlow]; 

}

- (void)stopTunnelWithReason:(NEProviderStopReason)reason completionHandler:(void (^)(void))completionHandler {
// Add code here to start the process of stopping the tunnel.
_stopHandler = completionHandler;

if(_vpnReachability.isTracking) {
    [_vpnReachability stopTracking];
}

[self.vpnAdapter disconnect];

}

`

ss-abramchuk commented 3 years ago

Hi @jialovegirl,

First of all I would recommend to follow advice from NSLocalizedDescription and check underlying error details during debug. Also, you may try to set configuration.tunPersist = YES to avoid resetting of the tunnel. As for preventing establishing VPN connection from the settings I'm afraid I can't help with that. It is the matter of the app implementation and it requires research.

jialovegirl commented 3 years ago

@ss-abramchuk Thank you for your reply