ioslocalauthenticationcore-authentication

LAContext().biometryType returns .none on iPhone X


I'm facing a problem with CoreAuthentication.

I have called canEvaluatePolicy:error: as the documentation ask for but the result is always .none.

fileprivate let biometricsType: SecurityBiometrics = {
        var error: NSError?
        let evaluated = LAContext().canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error)
        if #available(iOS 11.0, *) {
            if LAContext().biometryType == .faceID { return .faceID }
            if LAContext().biometryType == .touchID { return .touchID }
        } else {
            if (evaluated || (error?.code != LAError.touchIDNotAvailable.rawValue)) {
                return .touchID
            }
        }
        return .none
    }()

// biometricsType returns `.none`

A error is showing up on the console :

[LAClient] initWithExistingContext -> (null), Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.CoreAuthentication.daemon was invalidated from this process." UserInfo={NSDebugDescription=The connection to service named com.apple.CoreAuthentication.daemon was invalidated from this process.}

It already have worked before, but now (without any changes) it's still returning .none.

Do you have run into the same error ?


Solution

  • You didn't share full error message. Here is full error message:

    [LAClient] initWithExistingContext -> (null), Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.CoreAuthentication.daemon was invalidated from this process." UserInfo={NSDebugDescription=The connection to service named com.apple.CoreAuthentication.daemon was invalidated from this process.} 2018-03-29 13:42:37.866753+0530 Test[1505:35036] [LAClient] initWithExistingContext -> (null), Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.CoreAuthentication.daemon was invalidated from this process." UserInfo={NSDebugDescription=The connection to service named com.apple.CoreAuthentication.daemon was invalidated from this process.}

    In normal language, it says you have a problem with LAContext() which is initialised every time ([LAClient] initWithExistingContext -> (null)) in your code block. Use a single instance of LAContext.

    Try this and see:

    fileprivate let biometricsType: LABiometryType = {
        let laContext = LAContext()
        var error: NSError?
        let evaluated = laContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error)
    
        if let laError = error {
            print("laError - \(laError)")
            return .none
        }
    
        if #available(iOS 11.0, *) {
            if laContext.biometryType == .faceID { return .faceID }
            if laContext.biometryType == .touchID { return .touchID }
        } else {
            if (evaluated || (error?.code != LAError.touchIDNotAvailable.rawValue)) {
                return .touchID
            }
        }
        return .none
    }()
    
    // print biometricsType
    print("biometricsType - \(biometricsType.rawValue)")
    

    Result: biometricsType - 2

    Look at this snapshot:

    enter image description here