【问题标题】:iOS VPN auto disconnected after sometimeiOS VPN 一段时间后自动断开连接
【发布时间】:2020-04-14 15:23:44
【问题描述】:

我正在开发一个 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

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

【问题讨论】:

    标签: ios swift vpn nevpnmanager


    【解决方案1】:

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

    【讨论】:

    • 我不认为这是一个好主意,以前我使用 NEVPNProtocolIPSec 并遇到了很多问题,然后我决定使用 NEVPNProtocolIKEv2,所有其他问题都解决了,但我仍然面临这个问题。
    • hm 我不知道你的问题为什么会不幸出现,只是想知道因为我在使用 IKEV2 你之前遇到过什么样的问题
    • 如果您使用的是 IKEv2,请告诉我,您遇到过自动断开连接问题吗?
    • 不是现在..实际上我从来没有在超过 5 分钟内连接过 VPN。
    • 和她一样,但用户抱怨断开连接问题,需要解决。
    【解决方案2】:

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

    【讨论】:

    • 已设置按需连接,仍然无法解决此问题。如果你有配置,那是工作,请分享我会很感激。
    • 这就是我要说的:不可能以您认为的方式“解决问题”:您的按需配置是正确的,这就是您可以从 iOS 获得的全部内容,这是不可能的保持连接在后台打开
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2023-01-24
    • 2013-07-22
    • 1970-01-01
    相关资源
    最近更新 更多