VPNTunnelProviderManager

After running the code the status showing invalid and VPN Disconnected automatically. What is the serveraddress should I use? Here is my VPNConfiguration code.

private func initVPNTunnelProviderManager() {

        NETunnelProviderManager.loadAllFromPreferences { (savedManagers: [NETunnelProviderManager]?, error: Error?) in

            if let error = error {

                print(error)

            }

            if let savedManagers = savedManagers {

                if savedManagers.count > 0 {

                    self.vpnManager = savedManagers[0]

                }

            }

         

            self.vpnManager.loadFromPreferences(completionHandler: { (error:Error?) in

                if let error = error {

                    print(error)

                }

             

                let providerProtocol = NETunnelProviderProtocol()

                providerProtocol.providerBundleIdentifier = self.tunnelBundleId

             

                providerProtocol.providerConfiguration = [“port”: self.serverPort,

                                                          “server”: self.serverAddress,

                                                          “ip”: self.ip,

                                                          “subnet”: self.subnet,

                                                          “mtu”: self.mtu,

                                                          “dns”: self.dns

                ]

                providerProtocol.serverAddress = self.serverAddress

                self.vpnManager.protocolConfiguration = providerProtocol

                self.vpnManager.localizedDescription = “VPN Returns”

                self.vpnManager.isEnabled = true

             

                self.vpnManager.saveToPreferences(completionHandler: { (error:Error?) in

                    if let error = error {

                        print(error)

                    } else {

                        print(“Save successfully”)

                    }

                })

                self.VPNStatusDidChange(nil)

             

            })

        }

    }

Then i wrote the VPN status on the button action. NEVPNStatusInvalid = 0 NEVPNStatusDisconnected = 1 NEVPNStatusConnecting = 2 NEVPNStatusConnected = 3 NEVPNStatusReasserting = 4 NEVPNStatusDisconnecting = 5 Now the status is 0 and 5

Powered by WPeMatico

About

You may also like...

Comments are closed.