简体   繁体   English

stopVPNTunnel 没有断开 iOS 中的 VPN 连接

[英]stopVPNTunnel is not disconnecting the VPN connection in iOS

I have implemented one successful vpn connection.我已经实现了一个成功的 vpn 连接。 But When i close and Open app while the VPN is connected, then i can't disconnect the VPN.但是当我在连接 VPN 时关闭并打开应用程序时,我无法断开 VPN。

public func connectVPN() {
    //For no known reason the process of saving/loading the VPN configurations fails.On the 2nd time it works
    Log.d(message:  "connectVPN")
    NSLog("ConnectVPN")
    self.vpnManager.loadFromPreferences(completionHandler: self.vpnLoadHandler)
    NotificationCenter.default.addObserver(forName: NSNotification.Name.NEVPNStatusDidChange, object: nil , queue: nil) {
        notification in
        let nevpnconn = notification.object as! NEVPNConnection
        let status = nevpnconn.status
        self.vpnDelegate?.checkNES(status: status)
    }
}

public func disconnectVPN() ->Void {
    Log.d(message:  "Disconnect VPN Called")
    Log.d(message: "Log Disconnect VPN Called")
    
    print("vpnManager:disconnectVPN \(self.vpnManager.connection) ") // object available
    
    self.vpnManager.connection.stopVPNTunnel()
}

I could not find out why it is not disconnecting.我不知道为什么它没有断开连接。

Call stopVPNTunnel() inside loadFromPreferences closure.loadFromPreferences闭包中调用stopVPNTunnel()

NEVPNManager.shared().loadFromPreferences { error in
  assert(error == nil, "Failed to load preferences: \(error!.localizedDescription)")
  NEVPNManager.shared().connection.stopVPNTunnel()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM