Biometry Type when user denied biometry usage
Asked Answered
T

1

4

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

Tabling answered 23/11, 2017 at 10:52 Comment(0)
V
7

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

Vilipend answered 24/11, 2017 at 9:52 Comment(2)
@Juan iOS 10 may only know the support (or not) of touch id, I'm talking about the result coming from the method canEvaluatePolicy which return true whether the device has physically the fingerprint sensor on it. To be sure about that, on iOS 10 you can use the policy LAPolicyDeviceOwnerAuthenticationWithBiometrics. The scenario where you run iOS 10 on iPhone X can't be considered, as it comes already with iOS 11, so there is not point to have biometryType on iOS10, as it return true only if you have a fingerprint sensor on it :) I've edited my answers specifying this for the iOS 10 caseVilipend
I'm not completely sure, but this code may crash on 11.0.0, Had an issue with an app I work on, but were comparing to .faceID, not .typeFaceID, the former is not available until 11.0.1, not clear on the latter, and I don't have a device or simulator with 11.0 on it to check .Abnaki

© 2022 - 2024 — McMap. All rights reserved.