ios - 检查 FaceID 是否启用

标签 ios swift biometrics face-id passcode

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

相关文章:

ios - Swift 自定义 UITableViewCell 标签始终为零

ios - iOS中如何停止摇动手势?

iOS 生物认证 : Try Password work only after the second biometric fail attempt

biometrics - 有存储指纹和虹膜的开源数据库吗?

android - 找不到 BiometricPrompt 的支持库

ios - 缺少 SCNAudioPlayer 的 audioNode 属性

ios - 多个 UICollectionView 在同一布局中滚动

swift - 使用 slider 在 2 个图像之间转换

ios - 如何从 NSString 中捕获最后 4 个字符

ios - Xcode Swift 动画透明度错误