swift - 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")
}
}
}
}
}
解决方案
推荐阅读
- android - 如何从意图打开默认文件应用程序中的 DCIM/Camera 文件夹
- javascript - 这个包含大量 document.getElementById 的 JS 循环的正确语法是什么?
- python - 如何从 tkinter 中的一个类函数中获取值
- flutter - 'textSelectionHandleColor' 已弃用,不应使用
- javascript - 循环时如何处理未定义
- css - 当输入值为Angular Material中的LTR时如何使mat-label向右浮动(RTL语言)
- python - Groupby多列使用python pandas查找一列的唯一计数
- laravel - 如何从 Laravel 上的预加载中获取嵌套数据?
- c++ - 链接目标文件时的多重定义
- javascript - textContent 和 innerHtml 在函数内部不起作用