开发者社区> 问答> 正文

iOSVPN在某个时候自动断开连接

我正在处理一个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

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

展开
收起
游客5akardh5cojhg 2019-12-25 16:34:30 8689 0
1 条回答
写回答
取消 提交回答
  • 用以下方式更改您的VPN协议:NEVPNProtocolIPSec,也许它会对您有所帮助。

    2019-12-25 16:34:50
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
探索连接的最后十秒”落时”的网关 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载