简体   繁体   中英

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 ?

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM