生物识别类型 Bug 解决方法

CI Status Version License Platform

LocalAuthentication 框架的 LAContext 有一个名为 biometryType 的属性。它表示设备支持的生物识别认证类型。它本应在调用 LAContextcanEvaluatePolicy(_:error:) 之后设置。但在某些情况下,它没有被设置。这是 iOS 11.0.x 的一个 bug。

此外,如果在 iOS 11.0 上调用 biometryType,iOS 设备会崩溃。

(查看更多 bug 详情:http://www.openradar.me/radar?id=5061720007507968)

这个库为这些 bug 提供了解决方法。

用法

这个库仅提供了一个作为 LAContext 扩展的方法。它是 biometryTypeForWorkaround(with:)。它是 LAContextbiometryType 属性的替代品。你可以这样使用它

let context = LAContext()
var error: NSError?
let canEvaluate = context.canEvaluatePolicy(
    .deviceOwnerAuthenticationWithBiometrics,
    error: &error)

let biometryType = context.biometryTypeForWorkaround(
    with: error as? LAError)

注意

示例

要运行示例项目,首先克隆仓库,并从 Example 目录运行 pod install

安装

BiometryTypeBugWorkaround 可通过 CocoaPods 获取。要安装它,只需将以下行添加到你的 Podfile

pod 'BiometryTypeBugWorkaround'

作者

Manabu Nakazawa (@mshibanami)

许可

BiometryTypeBugWorkaround 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。