Type of biometrics when the user denied using biometrics

In our application, the user must register for the device biometrics in order to use it for authentication. The registration text and legal notes correspond to the corresponding biometrics (register to touch the ID or register the face ID) As I understand it, the type of biometrics can be obtained through LAContext, but if the user denies using biometrics, the context returns biometryType = .none

Any ideas that ask for screen size and compare with iphone X (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

+3
source share
1 answer

I have the same problem and I just found out that if you evaluate against the key LAPolicyDeviceOwnerAuthentication instead of LAPolicyDeviceOwnerAuthenticationWithBiometrics even after the user has denied permission, the assessment will succeed and you will get the correct bioometryType type. Your code will look 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 a touch identifier and a face identifier, it still returns YES, so you don’t know whether the device really has a hw biometric value or not with iOS below 11 (which does not set the biometriyType property)

Update

For devices with iOS version 10 or lower, you can use LAPolicyDeviceOwnerAuthenticationWithBiometrics, as usual, will behave correctly (returns true if the device supports a touch identifier), so this is just a matter of differentiating the current OS version :)

Let me know if this works :)

The best

+3
source

Source: https://habr.com/ru/post/1272784/


All Articles