用户拒绝使用生物特征时的生物特征类型 [英] Biometry Type when user denied biometry usage

查看:166
本文介绍了用户拒绝使用生物特征时的生物特征类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In our app, the user has to register to the device biometry in order to use it for authentication. The registration text and legal notes are according to the relevant biometry (register to touch ID or register to face ID) As far as I found, the biometry type is obtainable via the LAContext, but if the user denies usage of biometry, then the context returns biometryType=.none

除了询问屏幕尺寸并与iphone X(错误的错误代码)进行比较之外,还有其他想法吗?

Any ideas other that asking for the screen size and comparing to iphone X (bad bad code)?

    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
        }
    }

谢谢

推荐答案

我遇到了相同的问题,并且我刚刚发现,如果您使用键 LAPolicyDeviceOwnerAuthentication 而不是键进行评估, LAPolicyDeviceOwnerAuthenticationWithBiometrics ,即使用户拒绝了该权限,评估也会成功,并且您将获得正确的biometryType.您的代码就像

I've got the same identical issue, and I've just found out that if you evaluate against the key LAPolicyDeviceOwnerAuthentication instead of LAPolicyDeviceOwnerAuthenticationWithBiometrics, even after the user declined the permission, the evaluation succeeds and you get the correct biometryType. Your code would be like

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
    }
}

注意:在没有触摸ID和面部ID的设备上,它仍返回YES,因此您将不知道该设备是否具有低于11的iOS的生物统计学硬件(不是)公开属性biometriyType)

NOTE: on devices without touch id and face id, it still returning YES, so you would not know whether the device really has a biometric hw or not with iOS lower than 11 (which do not expose the property biometriyType)

更新

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

For devices with iOS version 10 or lower, you can use the LAPolicyDeviceOwnerAuthenticationWithBiometrics as usual, it will behave correctly (returning true whether the device supports the touch Id), so it's just a matter of differentiating the running OS version :)

让我知道它是否有效:)

Let me know if it works :)

最佳

这篇关于用户拒绝使用生物特征时的生物特征类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆