I want to test faceId/touchId mechanism in my app. I have following:
func auth(){
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
var reason: String = Strings.Common.unknownBiometryTip.value
if BiometricService.biometricType() == .touchID {
reason = Strings.Common.touchIDEnterTip.value
}
if BiometricService.biometricType() == .faceID {
reason = Strings.Common.faceIDEnterTip.value
}
context.evaluatePolicy(LAPolicy.deviceOwnerAuthentication, localizedReason: reason) { [weak self] (success, error) in
print("error \(error)")
if let error = error as? LAError, error.errorCode == Int(kLAErrorUserCancel) {
self?.cancelTapped?()
return
}
if success {
self?.authSucceed?()
}
else {
self?.authFailure?()
}
}
}
else {
print("Touch ID neither Face ID not available")
}
}
I actually can't test authFailure
block, because when i hit "not-matching face" button in XCode, it shows up pin entry view, and look like anything i type in handled as "correct".
I actually want callback anytime user have "wrong" face/touchId/pin entry attempt, but i can't figure out how to get it.