Biometry当用户拒绝使用生物测量时输入

Yas*_*kin 4 ios localauthentication iphone-x face-id

在我们的应用程序中,用户必须注册到设备biometry才能使用它进行身份验证.注册文本和法律注释是根据相关的生物统计学(注册到触摸ID或注册到面部ID)据我发现,生物测定类型可以通过LAContext获得,但如果用户拒绝使用生物测量,那么上下文返回biometryType = .none

任何其他要求屏幕尺寸和与iPhone X(坏的坏代码)比较的想法?

    static fileprivate var biometryType: DSLocalAuthenticationBiometryType {
        let context = LAContext()

        var error: NSError?
        let _ = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)

        if #available(iOS 11.0, *) {

            return context.biometryType == .typeFaceID ? .typeFaceID : .none
        }
        else {
            return .none
        }
    }
Run Code Online (Sandbox Code Playgroud)

谢谢

Luc*_*aco 6

我有同样的问题,我刚刚发现,如果你对LAPolicyDeviceOwnerAuthentication而不是LAPolicyDeviceOwnerAuthenticationWithBiometrics进行评估,即使用户拒绝了许可,评估也会成功,你得到正确的biometryType.你的代码就像

static fileprivate var biometryType: DSLocalAuthenticationBiometryType {
    let context = LAContext()

    var error: NSError?
    let _ = context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)

    if #available(iOS 11.0, *) {

        return context.biometryType == .typeFaceID ? .typeFaceID : .none
    }
    else {
        return .none
    }
}
Run Code Online (Sandbox Code Playgroud)

注意:在没有touch id和face id的设备上,它仍然返回YES,所以你不知道设备是否真的具有生物特征hw,iOS是否低于11(不暴露属性biometriyType)

更新

对于iOS版本为10或更低版本的设备,您可以像往常一样使用LAPolicyDeviceOwnerAuthenticationWithBiometrics,它将正常运行(无论设备是否支持触摸ID,都返回true),因此只需区分正在运行的操作系统版本:)

让我知道它是否有效:)

最好