请参见下面的代码。每当我在运行iOS 7的iPhone 5c上运行此代码时,在let管理器上都会收到EXC_BAD_ACCESS错误:NEVPNManager = NEVPNManager.sharedManager()行。
我将如何解决这个问题,或者有没有解决的办法?
提前致谢。
let manager: NEVPNManager = NEVPNManager.sharedManager()
var p = NEVPNProtocolIPSec()
manager.`protocol` = p
let pw = "pw";
p.username = "un"
p.passwordReference = pw.dataUsingEncoding(NSUTF8StringEncoding)
p.serverAddress = "server"
p.authenticationMethod = NEVPNIKEAuthenticationMethod.SharedSecret
//p.sharedSecretReference = getPasscodeNSData("vpnSharedSecret")
p.useExtendedAuthentication = true
p.disconnectOnSleep = false
最佳答案
那是因为NEVPNManager是在iOS8上添加的,正如您在此Apple文档NetworkExtension Changes中所看到的那样
iOS 8.0 API差异
NEVPNManager.h(已添加)
添加了NEVPNManager
添加了NEVPNManager.connection
添加了NEVPNManager.enabled
添加了-[NEVPNManager loadFromPreferencesWithCompletionHandler:]
添加了NEVPNManager.localizedDescription
添加了NEVPNManager.onDemandEnabled
添加了NEVPNManager.onDemandRules
添加了NEVPNManager.protocol
添加了-[NEVPNManager removeFromPreferencesWithCompletionHandler:]
添加了-[NEVPNManager saveToPreferencesWithCompletionHandler:]
添加了+ [NEVPNManager sharedManager]
添加了NEVPNConfigurationChangeNotification
添加了NEVPNError
添加了NEVPNErrorConfigurationDisabled
添加了NEVPNErrorConfigurationInvalid
添加了NEVPNErrorConfigurationStale
添加了NEVPNErrorConnectionFailed
添加了NEVPNErrorDomain
添加了#def NEVPN_EXPORT
关于ios - 在Swift中创建NEVPNManager对象时出现问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30953038/