【问题标题】:LAContext().biometryType returns .none on iPhone XLAContext().biometryType 在 iPhone X 上返回 .none
【发布时间】:2018-09-07 09:09:45
【问题描述】:

我遇到了CoreAuthentication 的问题。

我已按照文档要求致电canEvaluatePolicy:error:,但结果始终为.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`

控制台上显示错误:

[LAClient] initWithExistingContext -> (null), 错误 Domain=NSCocoaErrorDomain Code=4099 "与服务的连接名为 com.apple.CoreAuthentication.daemon 从此失效 进程。" UserInfo={NSDebugDescription=与服务的连接名为 com.apple.CoreAuthentication.daemon 从此失效 过程。}

它以前已经工作过,但现在(没有任何更改)它仍然返回.none

您是否遇到过同样的错误?

【问题讨论】:

  • How to test face-id - 这是完整的工作代码。您可以获取您的需求相关代码。
  • @Krunal The connection to service named com.apple.CoreAuthentication.daemon was invalidated from this process. 现在在控制台上显示两次,但现在可以正常工作了。谢谢!

标签: ios localauthentication core-authentication


【解决方案1】:

您没有分享完整的错误消息。这是完整的错误信息:

[LAClient] initWithExistingContext -> (null), Error Domain=NSCocoaErrorDomain Code=4099 “与名为 com.apple.CoreAuthentication.daemon 的服务的连接在此进程中无效。” UserInfo={NSDebugDescription=与名为 com.apple.CoreAuthentication.daemon 的服务的连接在此进程中无效。} 2018-03-29 13:42:37.866753+0530 测试 [1505:35036] [LAClient] initWithExistingContext -> (null),错误域 = NSCocoaErrorDomain 代码 = 4099“与名为 com.apple.CoreAuthentication.daemon 的服务的连接无效从这个过程中。” UserInfo={NSDebugDescription=与名为 com.apple.CoreAuthentication.daemon 的服务的连接在此进程中无效。}

在普通语言中,它表示您的代码块中的 LAContext() 每次都被初始化 ([LAClient] initWithExistingContext -> (null)) 有问题。使用 LAContext 的单个实例。

试试这个看看:

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)")

结果:biometricsType - 2

看看这个快照:

【讨论】:

  • 非常感谢,我从没想过单实例.. 我的错!
猜你喜欢
  • 2018-08-14
  • 1970-01-01
  • 1970-01-01
  • 2019-10-27
  • 1970-01-01
  • 2018-01-04
  • 2022-01-21
  • 2019-11-27
相关资源
最近更新 更多