Bar*_*man 10 vpn xcode keychain swift mac-catalyst
我正在尝试使用 Mac Catalyst 在 Mac OS 平台上运行我的 VPN iOS 应用程序。
我的代码适用于 iOS 应用程序,但不知何故它不适用于 Mac OS。
VPN 未连接。但似乎可以在 Mac Catalina 上的系统偏好设置中的网络中使用。
它还包含我们的 VPN 连接信息,例如服务器名称、密码。这些都对。在钥匙串中,我会看到 psk 和密码。据我所知,psk 是一个共享密钥。但是如果我点击从网络部分连接,我会遇到没有提供共享密钥的错误。但实际上它存储在钥匙串访问中。
我的连接类型是 IPSec。
在 Xcode 中点击连接 VPN 按钮后,我会看到
复制内容失败,返回 SecKeychainItemCopyContent 无法检索此项目的内容错误<在控制台中
我把我的连接部分放在这里。但为了提醒我的代码在 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")
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
400 次 |
| 最近记录: |