是否有方法检测用户在使用"LAContext().evaluatePolicy(.deviceOwnerAuthentication,localizedReason: someReason后是否拒绝了生物识别技术(faceID)“?
例如,
biometrics
。
在关闭并重新打开应用程序之前,"LAContext().canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,error: nil)似乎canEvaluatePolicy返回true )。
我希望能够提醒用户,他们可以在他们的应用程序设置中打开faceID。
发布于 2021-10-25 02:49:38
似乎没有办法确定你在问题中所描述的情况。
我注意到,canEvaluatePolicy的文档声明:
不存储此方法的返回值,因为它可能由于系统中的更改而发生更改。例如,用户在调用此方法后可能会禁用Touch ID。但是,在应用程序进入后台之前,报告的值确实保持一致。
然而,在测试中,即使将应用程序放到后台也不会改变canEvaluatePolicy返回的值。
正如您在问题中所指出的,在重新启动应用程序之前,返回的值不会改变。您还会看到,如果您进入首选项并切换您的应用程序的生物特征设置,那么您的应用程序实际上是重新启动的。同样的过程也发生在其他与隐私相关的设置上。
您可以在随后的发布中提供生物识别认证,如果您确定它已被拒绝,但当用户已经做出决定时,您应该谨慎地注意窃听用户。
您可以使用的另一种方法是尝试LAContext().evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "reason"),如果由于生物特征识别被拒绝而失败,请使用LAContext().evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "reason")重试身份验证,这将立即提示输入密码。
发布于 2021-10-24 22:42:45
// Declare You're own Error type to handle possible errors
enum BiometryError: Swift.Error, LocalizedError {
case unavailable, // Biometry unavailable
failed, // Can't verify
cancel, // User pressed cancel
failback, // User choose password
locked, // Biometry is locked
enrolled, // Biometry not setup
succsess // Success
init(error: LAError) {
switch error {
case LAError.authenticationFailed:
self = .failed
case LAError.userCancel:
self = .cancel
case LAError.userFallback:
self = .failback
case LAError.biometryNotAvailable:
self = .unavailable
case LAError.biometryNotEnrolled:
self = .enrolled
case LAError.biometryLockout:
self = .locked
default:
self = .unavailable
}
}
public var errorDescription: String? {
switch self {
case .unavailable:
return "Unavailable"
case .failed:
return "Failed"
case .cancel:
return "Cancel"
case .failback:
return "Failback"
case .locked:
return "Locked"
case .enrolled:
return "Enrolled"
case .succsess:
return "Succsess"
}
}
}
// Authenticate method
func authenticateBiometry(reply callback: @escaping (Bool, BiometryError?) -> Void) {
LAContext().evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "reason") { success, error in
if let error = error as? LAError, !success {
// Here in this callback You can handle error and show alert if You want
callback(false, BiometryError(error: error))
} else {
// Success
callback(true, nil)
}
}
}https://stackoverflow.com/questions/69700953
复制相似问题