我在本地身份验证中更改视图控制器时遇到问题。当所有代码在success 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)
}
答案 0 :(得分:0)
我想通了!!似乎本地身份验证需要一个布尔IF语句包含所有代码。我不确定这是否属实......但它对我有用。