ashForIos
ashForIos

Reputation: 399

Check FaceID is enabled or not

I want to get the string for the current lock type used in the device, whether it is FaceID, touchID or PassCode. Below is my code :-

func getBiometricType() -> String {
    var biometricType: Global.BiometricType {
        let context = LAContext()
        var error: NSError?
        guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else { return .none }
        if #available(iOS 11.0, *) {
            switch context.biometryType {
                case .touchID:
                    return .touchID
                case .faceID:
                    return .faceID
                case .none:
                    return .none
            }
        } else {
            guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else { return .none }
            return context.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil) ?
     .touchID : .PIN
        }
    }
    return biometricType.rawValue
}

But this canEvaluatePolicy only checks whether the device supports biometric or not. Even when the FaceID is not set up yet but the Passcode is enabled, it does not give info regarding the passcode. As I need to show the type enabled is "Passcode". Is there any way to achieve this?

Upvotes: 2

Views: 6007

Answers (1)

Lal Krishna
Lal Krishna

Reputation: 16160

You have to use LAPolicy.deviceOwnerAuthenticationWithBiometrics.

As per apple docs:

If Touch ID or Face ID is not available or not enrolled, policy evaluation fails. After three unsuccessful Touch ID or Face ID attempts in a row, policy evaluation will fail. Both Touch ID and Face ID authentication are disabled after five unsuccessful attempts, requiring the user to enter the device passcode in order to be reenabled.

LAPolicy.deviceOwnerAuthentication enables:

If Touch ID or Face ID is available, enrolled, and not disabled, the user is asked for that first. Otherwise, they are asked to enter the device passcode. If the device passcode is not enabled, policy evaluation fails. Passcode authentication is disabled after 6 unsuccessful attempts, with progressively increasing delays between them.

Upvotes: 2

Related Questions