error configuration invalid when I try to connect with a proxy config

I am trying to connect with a proxy VPN, all of the confines are correct, but I don't know why I got error
here is my code:

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 = "NEPacketTunnelVPNDemoConfig"
                self.vpnManager.isEnabled = true
                
                self.vpnManager.saveToPreferences(completionHandler: { (error:Error?) in
                    if let error = error {
                        print(error)
                    } else {
                        print("Save successfully")
                        
                        do {
                            try self.vpnManager.connection.startVPNTunnel()
                            
                        } catch NEVPNError.configurationInvalid {
                            print("Failed to start tunnel (configuration invalid)")
                            
                        } catch NEVPNError.configurationDisabled {
                            print("Failed to start tunnel (configuration disabled)")
                        } catch {
                            print("Failed to start tunnel (other error)")
                        }
                    }
                })
                
            })
        }

Replies

I am trying to connect with a proxy VPN, all of the confines are correct, but I don't know why I got error

Looking through your code, I don’t see any place you’re setting a proxy configuration (that is, I don’t ee a reference to

providerProtocol.proxySettings
). Did you elide something here?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"