首页 > 解决方案 > VPN 在 Mac Catalyst 上不工作 SecKeychainItemCopyContent 返回 无法检索此项目的内容

问题描述

我正在尝试使用 Mac Catalyst 在 Mac OS 平台上运行我的 VPN iOS 应用程序。

我的代码适用于 iOS 应用程序,但不知何故不适用于 Mac OS。

VPN 未连接。但似乎在 Mac Catalina 上的系统偏好设置中的网络中可用。

它还包含我们的 VPN 连接信息,例如服务器名称、密码。这些都是正确的。在钥匙串中,我会看到 psk 和密码。据我所知 psk 是共享密钥。但是,如果我单击从网络部分进行连接,我会遇到没有提供共享密钥的错误。但实际上它存储在钥匙串访问中。

我的连接类型是 IPSec。

在 Xcode 之后点击连接 VPN 按钮我会看到

复制内容失败,返回 SecKeychainItemCopyContent The contents of this item can be retrieved error< in console

我把我的连接部分放在这里。但是提醒我的代码在 iOS 应用程序上没有任何错误。相同的代码也不适用于 Mac OS。那就是问题所在。

任何帮助都会很棒!

public func connectIKEv2(config: Configuration, onError: @escaping (String)->Void) {
        let p = NEVPNProtocolIPSec()
        if config.pskEnabled {
            p.authenticationMethod = NEVPNIKEAuthenticationMethod.sharedSecret
        } else {
            p.authenticationMethod = NEVPNIKEAuthenticationMethod.none
        }
        p.serverAddress = config.server
        p.disconnectOnSleep = false
        p.username = config.account
        p.passwordReference = config.getPasswordRef()
        p.sharedSecretReference = config.getPSKRef()
        // I catch password and psk without no mistake.
        p.useExtendedAuthentication = true

        // two lines bellow may depend of your server configuration
        p.remoteIdentifier = config.server
        //  p.localIdentifier = config.account

        loadProfile { _ in
            self.manager.protocolConfiguration = p
            if config.onDemand {
                self.manager.onDemandRules = [NEOnDemandRuleConnect()]
                self.manager.isOnDemandEnabled = true
            }
            self.manager.isEnabled = true
            self.saveProfile { success in
                if !success {
                    onError("Unable to save vpn profile")
                    return
                }
                self.loadProfile() { success in
                    if !success {
                        onError("Unable to load profile")
                        return
                    }
                    let result = self.startVPNTunnel()
                    if !result {
                        onError("Can't connect")
                    }
                }
            }
        }
    }

标签: swiftxcodevpnkeychainmac-catalyst

解决方案


推荐阅读