gpt4 book ai didi

ios - 检查 FaceID 是否启用

转载 作者:行者123 更新时间:2023-11-28 13:54:45 27 4
gpt4 key购买 nike

我想获取设备中当前使用的锁类型的字符串,无论是 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com