Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS VPN在某个时间后自动断开_Ios_Swift_Vpn_Nevpnmanager - Fatal编程技术网

iOS VPN在某个时间后自动断开

iOS VPN在某个时间后自动断开,ios,swift,vpn,nevpnmanager,Ios,Swift,Vpn,Nevpnmanager,我正在开发一个VPN应用程序,VPN工作正常,但15-20分钟后,它会自动断开连接。 这是我正在使用的配置 let vpnProtocol = NEVPNProtocolIKEv2() vpnProtocol.username = CredentialsManager.shared.accessToken vpnProtocol.localIdentifier = CredentialsManager.shared.accessToken

我正在开发一个VPN应用程序,VPN工作正常,但15-20分钟后,它会自动断开连接。 这是我正在使用的配置

        let vpnProtocol = NEVPNProtocolIKEv2()
        vpnProtocol.username = CredentialsManager.shared.accessToken
        vpnProtocol.localIdentifier = CredentialsManager.shared.accessToken

        print("VPN Connecting to \(self.region.name ?? "Error! Must be a valid region name!")")

        if let region = self.region {
          f
            vpnProtocol.serverAddress = region.serverAddress
            vpnProtocol.remoteIdentifier = region.serverAddress
        }

        let encodedIdentifier = "Secret Password".data(using: .utf8)!
        let item = [kSecClass: kSecClassGenericPassword,
                    kSecAttrGeneric: encodedIdentifier,
                    kSecAttrAccount: encodedIdentifier,
                    kSecMatchLimit: kSecMatchLimitOne,
                    kSecReturnPersistentRef: kCFBooleanTrue as Any,
                    kSecAttrService: "XYZ"] as [CFString : Any]

        var passwordReference: CFTypeRef?
        SecItemCopyMatching(item as CFDictionary, &passwordReference)

        vpnProtocol.passwordReference = passwordReference as? Data
        vpnProtocol.authenticationMethod = .none
        vpnProtocol.useExtendedAuthentication = true

        vpnProtocol.ikeSecurityAssociationParameters.encryptionAlgorithm =
            .algorithmAES256GCM
        vpnProtocol.ikeSecurityAssociationParameters.integrityAlgorithm = .SHA384
        vpnProtocol.ikeSecurityAssociationParameters.diffieHellmanGroup = .group14

        vpnProtocol.childSecurityAssociationParameters.encryptionAlgorithm = .algorithmAES256GCM
        vpnProtocol.childSecurityAssociationParameters.integrityAlgorithm = .SHA384
        vpnProtocol.childSecurityAssociationParameters.diffieHellmanGroup = .group14

        vpnProtocol.disconnectOnSleep = false

        self.vpnManager.protocolConfiguration = vpnProtocol
        let connectRule = NEOnDemandRuleConnect()
        connectRule.interfaceTypeMatch = .any

        self.vpnManager.onDemandRules = [connectRule]
        self.vpnManager.isOnDemandEnabled = self.connectOnDemand
        self.vpnManager.localizedDescription = "XYZ VPN"
        self.vpnManager.isEnabled = true

请帮助我,如何识别导致自动断开连接的问题。

使用以下命令更改您的VPN协议:NEVPNProtocolIPSec
也许它会对您有所帮助。

您已经进行了配置,所以当您下次访问资源时,它会自动连接回来。iOS上的VPN就是这样工作的,它总是在空闲时关闭连接。

我不知道这是个好主意,以前我使用NEVPNProtocolIPSec,遇到了很多问题,然后我决定使用NEVPNProtocolIKEv2,所有其他问题都解决了,但我仍然面临着这个问题。嗯,我不知道你的问题为什么会不幸出现,但我只是想知道,因为我使用的是IKEV2,你以前遇到过什么样的问题如果你使用IKEV2,请告诉我,你遇到了自动断开连接的问题?不是现在。。事实上,我从来没有连接VPN超过5分钟。同一个用户,但用户抱怨断开连接问题,需要解决。已设置按需连接,仍然无法解决此问题。如果你有配置,这是工作,请分享我会很感激。这就是我说的:这是不可能的“解决问题”的方式,你认为:你的按需配置是正确的,这是所有你可以从iOS,这是不可能保持连接在后台打开