我正在尝试在我的应用中实施TouchID验证。我找到了许多解释如何做的例子(我做了)但事情是我不知道如果他/她想要给用户输入他/她的密码的可能性。 而且我想了解关闭我的应用程序的最佳方法,例如用户决定按下TouchID警报视图中的“取消”按钮。谢谢!
这是我的代码:
func validaIdentidad(){
var touchIDContext = LAContext()
var msgError : NSError?
var alerta = UIAlertController(title:"", message:"", preferredStyle: UIAlertControllerStyle.Alert)
alerta.addAction(UIAlertAction(title: "Understand", style: UIAlertActionStyle.Cancel, handler: {alertAction in
alerta.dismissViewControllerAnimated(true, completion: nil)}))
if touchIDContext.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &msgError) {
touchIDContext.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics,
localizedReason: "Please authenticate using your fingerprint",
reply: {(success: Bool, error: NSError!) -> Void in
if success {
//si valida, dejo abrir la app
self.transicion()
} else {
alerta.title = "Error"
switch error!.code {
case LAError.UserCancel.toRaw():
alerta.message = "Accion cancelada"
self.presentViewController(alerta, animated:true, completion:nil)
exit(0)
case LAError.AuthenticationFailed.toRaw():
alerta.message = "Error verificando tu identidad"
case LAError.UserFallback.toRaw():
alerta.message = "Usuario quiero ingresar passcode"
default:
alerta.message = "Error genérico"
}
//exit(0)
//self.presentViewController(alerta, animated:true, completion:nil)
}
})
}
else {
alerta.title = "Nope!"
switch msgError!.code {
case LAError.TouchIDNotAvailable.toRaw():
alerta.message = "Este dispositivo no tiene Touch ID"
case LAError.TouchIDNotEnrolled.toRaw():
alerta.message = "No se ha configurado el Touch ID"
case LAError.PasscodeNotSet.toRaw():
alerta.message = "No se ha configurado un PassCode"
default:
alerta.message = "Error Genérico"
}
self.presentViewController(alerta, animated:true, completion:nil)
}//cierre else
}//cierre func ValidaIdentidad