LocalAuthentication
框架的 LAContext
有一个名为 biometryType
的属性。它表示设备支持的生物识别认证类型。它本应在调用 LAContext
的 canEvaluatePolicy(_:error:)
之后设置。但在某些情况下,它没有被设置。这是 iOS 11.0.x 的一个 bug。
此外,如果在 iOS 11.0 上调用 biometryType,iOS 设备会崩溃。
(查看更多 bug 详情:http://www.openradar.me/radar?id=5061720007507968)
这个库为这些 bug 提供了解决方法。
这个库仅提供了一个作为 LAContext
扩展的方法。它是 biometryTypeForWorkaround(with:)
。它是 LAContext
的 biometryType
属性的替代品。你可以这样使用它
let context = LAContext()
var error: NSError?
let canEvaluate = context.canEvaluatePolicy(
.deviceOwnerAuthenticationWithBiometrics,
error: &error)
let biometryType = context.biometryTypeForWorkaround(
with: error as? LAError)
canEvaluatePolicy(_:error:)
之前,请勿调用此方法。它没有默认值 (none
)。要运行示例项目,首先克隆仓库,并从 Example 目录运行 pod install
。
BiometryTypeBugWorkaround 可通过 CocoaPods 获取。要安装它,只需将以下行添加到你的 Podfile
pod 'BiometryTypeBugWorkaround'
Manabu Nakazawa (@mshibanami)
BiometryTypeBugWorkaround 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。