本地身份验证不更改视图控制器
Local Authentication not changing view controllers
我在更改本地身份验证中的视图控制器时遇到问题。当所有代码都在成功的 if 语句中执行时,即使我告诉它,视图控制器也不会更改。我已经尝试了我所知道的一切,但没有任何效果。这是我的本地验证码。
let authentication = LAContext()
var authenticationError: NSError?
authentication.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &authenticationError)
if (authenticationError != nil) {
// Authentication Not available for this version of iOS
self.gotoMainViewController()
} else {
authentication.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Access Passy using Touch ID") {
(success, error) in
if (error != nil) {
// There was an error - user likley pressed cancel
print(error?.localizedDescription)
} else {
if (success) {
dispatch_async(dispatch_get_main_queue()) {
self.gotoMainViewController()
}
} else {
self.showFailedTouchIDError.showAlert()
}
}
}
}
这是 gotoMainViewController() 代码。
func gotoMainViewController() {
let viewController = MainViewController()
self.navigationController?.pushViewController(viewController, animated: true)
}
我明白了!!似乎本地身份验证需要一个布尔 IF 语句来包装所有代码。我不确定这是否属实...但它对我有用。
我在更改本地身份验证中的视图控制器时遇到问题。当所有代码都在成功的 if 语句中执行时,即使我告诉它,视图控制器也不会更改。我已经尝试了我所知道的一切,但没有任何效果。这是我的本地验证码。
let authentication = LAContext()
var authenticationError: NSError?
authentication.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &authenticationError)
if (authenticationError != nil) {
// Authentication Not available for this version of iOS
self.gotoMainViewController()
} else {
authentication.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Access Passy using Touch ID") {
(success, error) in
if (error != nil) {
// There was an error - user likley pressed cancel
print(error?.localizedDescription)
} else {
if (success) {
dispatch_async(dispatch_get_main_queue()) {
self.gotoMainViewController()
}
} else {
self.showFailedTouchIDError.showAlert()
}
}
}
}
这是 gotoMainViewController() 代码。
func gotoMainViewController() {
let viewController = MainViewController()
self.navigationController?.pushViewController(viewController, animated: true)
}
我明白了!!似乎本地身份验证需要一个布尔 IF 语句来包装所有代码。我不确定这是否属实...但它对我有用。