我想获取设备中当前使用的锁定类型的字符串,无论是 FaceID、touchID 还是 PassCode。下面是我的代码:-
func getBiometricType() -> String {
var biometricType: Global.BiometricType {
let context = LAContext()
var error: NSError?
guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else { return .none }
if #available(iOS 11.0, *) {
switch context.biometryType {
case .touchID:
return .touchID
case .faceID:
return .faceID
case .none:
return .none
}
} else {
guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else { return .none }
return context.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil) ?
.touchID : .PIN
}
}
return biometricType.rawValue
}
但是这个 canEvaluatePolicy 仅检查设备是否支持生物识别。即使尚未设置 FaceID 但已启用密码,它也不会提供有关密码的信息。因为我需要显示启用的类型是“密码”。有什么办法可以实现这一点吗?
最佳答案
您必须使用LAPolicy.deviceOwnerAuthenticationWithBiometrics
.
根据苹果文档:
If Touch ID or Face ID is not available or not enrolled, policy evaluation fails. After three unsuccessful Touch ID or Face ID attempts in a row, policy evaluation will fail. Both Touch ID and Face ID authentication are disabled after five unsuccessful attempts, requiring the user to enter the device passcode in order to be reenabled.
LAPolicy.deviceOwnerAuthentication 启用:
If Touch ID or Face ID is available, enrolled, and not disabled, the user is asked for that first. Otherwise, they are asked to enter the device passcode. If the device passcode is not enabled, policy evaluation fails. Passcode authentication is disabled after 6 unsuccessful attempts, with progressively increasing delays between them.
关于ios - 检查 FaceID 是否启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54037462/