8 Replies
      Latest reply on Feb 3, 2017 2:51 AM by keeshux
      adriansy Level 1 Level 1 (0 points)

        Hi , I have issue when starting VPN tunnel. My code load and save preference fine,

         

        Also I can see the profile that being created from my app in Setting->General->VPN. However when i try to run "self.targetManager.connection.startVPNTunnel()", it give me NEVPNErrorDomain Code=1

         

        This is my code

         

        self.targetManager.loadFromPreferencesWithCompletionHandler { error in
                  
            let newManager = NETunnelProviderManager()
            newManager.localizedDescription = "CustomVPN"
            newManager.protocolConfiguration = NETunnelProviderProtocol()
            newManager.protocolConfiguration?.serverAddress = "xxx.xxx.xxx.xxx"
            newManager.enabled = true
                  
            self.targetManager = newManager
                  
            self.targetManager.saveToPreferencesWithCompletionHandler{ error in
            //Handle error or success
            if (error == nil) {
                  if self.targetManager.connection.status == .Disconnected || self.targetManager.connection.status == .Invalid {
                        do {
                              NSLog("Try To Connect")
                              try self.targetManager.connection.startVPNTunnel()
                        } catch {
                              NSLog("Failed to start vpn: \(error)")
                        }
                  } else {
                        NSLog("Try To Disconnect")
                        self.targetManager.connection.stopVPNTunnel()
                  }
            }
            }
        }
        
        

         

        Thanks in advance

        • Re: Cannot Start VPN Tunnel NEVPNErrorDomain Code=1
          eskimo Apple Staff Apple Staff (12,275 points)

          The codes for NEVPNErrorDomain are defined in <NetworkExtension/NEVPNManager.h>.  This error, 1, is NEVPNErrorConfigurationInvalid.

          When you get this error does anything show up in the iOS device’s system log?

          Share and Enjoy

          Quinn "The Eskimo!"
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: Cannot Start VPN Tunnel NEVPNErrorDomain Code=1
              adriansy Level 1 Level 1 (0 points)

              Thanks for reply, Yea, I read about configuration invalid from header, but I am not sure what is wrong, cause I use same VPNManager configuration from Simple Tunnel sample code.

               

              I can connect to server if I turn on VPN manually from Setting but not automatically from my app

               

              This is the code for my startTunnel function

               

              let endpoint: NWHostEndpoint = NWHostEndpoint(hostname: "xxx.xxx.xxx.xxx", port: "xxxx")
                  
              connection = provider.createUDPSessionToEndpoint(endpoint, fromEndpoint: nil)
                  
              let options: NSKeyValueObservingOptions=[.Initial, .New];
              connection!.addObserver(self, forKeyPath: "state", options: options, context: &connection)
              
              
              

               

              This is the error that i get from device

               

              Nov 16 10:52:34 iPhone-5C nesessionmanager[262] <Notice>: Failed to load configuration with ID <__NSConcreteUUID 0x16e728f0> 6D5CA841-6726-4F41-98F4-E4A9C65231A1

              Nov 16 10:52:34 iPhone-5C nesessionmanager[262] <Notice>: Failed to create a session with type 1 and configuration ID <__NSConcreteUUID 0x16e728f0> 6D5CA841-6726-4F41-98F4-E4A9C65231A1

              Nov 16 10:52:34 iPhone-5C configd[30] <Notice>: network changed

              Nov 13 09:27:47 iPhone-5C <Warning>: Failed to start vpn: Error Domain=NEVPNErrorDomain Code=1 "(null)"

              Nov 13 09:27:47 iPhone-5C nesessionmanager[262] <Notice>: NESMVPNSession[xxxxxx]: status changed to disconnecting

              Nov 13 09:27:47 iPhone-5C nesessionmanager[262] <Notice>: NESMVPNSession[xxxxxx]: status changed to invalid, last stop reason Configuration was removed

              Nov 13 09:27:47 iPhone-5C nesessionmanager[262] <Notice>: NESMVPNSession[xxxxxx]: status changed to invalid, last stop reason Configuration was removed

              Nov 13 09:27:47 iPhone-5C configd[30] <Notice>: network changed

                • Re: Cannot Start VPN Tunnel NEVPNErrorDomain Code=1
                  pncbose Level 1 Level 1 (0 points)

                  i get the same error if i am trying to start VPN using startVPNTunnel() after calling saveToPreferencesWithCompletionHandler(). I am using simpleTunnel app


                  Is there a catch here ? Looks like some timing issue. connection.status is returning Invalid


                  it works if i do it via Settings..


                  - Naveen

                    • Re: Cannot Start VPN Tunnel NEVPNErrorDomain Code=1
                      eskimo Apple Staff Apple Staff (12,275 points)

                      i get the same error if i am trying to start VPN using startVPNTunnel() after calling saveToPreferencesWithCompletionHandler().

                      I know this sounds weird but have you tried saving twice?  I haven’t looked at this from the packet tunnel provider side of things, but when dealing with Personal VPN I’ve noticed that the NEVPNConnection status doesn’t update on my first save (r. 23114999)-:

                      Share and Enjoy

                      Quinn "The Eskimo!"
                      Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                      let myEmail = "eskimo" + "1" + "@apple.com"

                  • Re: Cannot Start VPN Tunnel NEVPNErrorDomain Code=1
                    iOSerKi Level 1 Level 1 (0 points)

                    Thx! Saving twice also works for me!

                    But there is an another problem.... After using NEVPNManager and NEVPNProtocolIPSec to configure and save twice preferences succesfully, VPN- start triggered by button clicking, I also get a error message in console, like this:

                     

                    2016-09-28 16:28:42.162701 testVPN[1692:422941] Start error: The operation couldn’t be completed. (NEVPNErrorDomain error 2.)
                    

                     

                    Then I fix the error by selecting the "testVPN" manually in Setting->General->VPN, because I have one more Personal VPNs... -. -

                    http://upload-images.jianshu.io/upload_images/935058-98d9d8b14b9a943f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240

                     

                    So, how should I do for selecting "testVPN" automatically instead manually ? The user experience is terrible...

                    And then I found that the "VPN Master" hasn't the problem above.

                  • Re: Cannot Start VPN Tunnel NEVPNErrorDomain Code=1
                    Aricent Pochun Level 1 Level 1 (0 points)

                    I too face the same problem as adriansy and pncboseadriansy.

                     

                    startVPNTunnelAndReturnError call returns NEVPNErrorConfigurationInvalid error if I try to use it after saveToPreferencesWithCompletionHandler. Is there any update on this?

                     

                    Thanks