Biometry Type when user denied biometry usage

和自甴很熟 提交于 2019-12-07 09:21:15

问题


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

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

Thanks


回答1:


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

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)

Update

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 :)

Best



来源:https://stackoverflow.com/questions/47453743/biometry-type-when-user-denied-biometry-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!