BiometricAuthenticator 1.4.0

BiometricAuthenticator 1.4.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2018年10月
SPM支持 SPM

Chris Corea 维护。



  • 作者
  • Christopher Corea

BiometricAuthenticator

CI Status Version License Platform

使用方法

要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install

首要之事,任何计划使用 Face ID 验证的应用都必须在应用的 Info.plist 文件中包含 NSFaceIDUsageDescription 键。在 Xcode 的 plist 编辑器中,添加一个新行,开始输入以下内容: 隐私 - Face ID 使用描述(Xcode 应该会自动完成),然后跟上是您的使用字符串。

调用身份验证提示非常简单

import BiometricAuthenticator

let bioAuth = BiometricAuthenticator()

if bioAuth.isTouchIdEnabledOnDevice() || bioAuth.isFaceIdEnabledOnDevice() {
    bioAuth.authenticate(localizedReason: "Let's authenticate with biometrics!", successBlock: {
        // oh boy it worked!
    }, failureBlock: { (error) in
        if let error = error {
            switch error {
            default:
            // use the LAError code to handle the different error scenarios
            print("error: \(error.code)")
            }
        }
    })
}

BiometricAuthenticator 还可以确定当前设备是否具有生物识别功能,以及生物识别功能是否已启用。

import BiometricAuthenticator

let bioAuth = BiometricAuthenticator()

// check if the feature exists on the device
if bioAuth.isTouchIdSupportedOnDevice() {
    // check if the feature is enabled
    if bioAuth.isTouchIdEnabledOnDevice() {
        // Hooray! We can authenticate using Touch ID!
    }
}

// check if the feature exists on the device
if bioAuth.isFaceIdSupportedOnDevice() {
    // check if the feature is enabled
    if bioAuth.isFaceIdEnabledOnDevice() {
        // Hooray! We can authenticate using Face ID!
    }
}

或者如果您希望直接检查功能启用情况

import BiometricAuthenticator

let bioAuth = BiometricAuthenticator()

if bioAuth.isTouchIdEnabledOnDevice() {
    ...
}

if bioAuth.isFaceIdEnabledOnDevice() {
    ...
}

处理身份验证错误

BiometricAuthenticator 依赖于 Local Authentication 模块提供的错误代码。以下是与处理它们相关的相关信息。

appCancel - 应用取消了生物识别提示

authenticationFailed - 提供的指纹或面容在 iOS 中没有被识别

biometryLockout - 由于多次失败的生物识别,用户已被锁定生物识别认证,因此身份验证无法继续。

biometryNotAvailable - 认证无法启动,因为设备不支持生物识别功能。

biometryNotEnrolled - 认证无法启动,因为用户尚未注册生物识别。

passcodeNotSet - 认证无法启动,因为设备上未设置密码。

systemCancel - 系统已取消认证(可能在认证对话框处于活动状态时另一个应用占据了前景)。

userCancel - 用户点击认证对话框中的取消选项取消认证。

userFallback - 认证已取消,因为用户在认证对话框中点击了回退按钮,但认证策略没有可用的回退。

需求

Xcode 8+, iOS 9.0+

安装

BiometricAuthenticator 通过 CocoaPods 提供。要安装它,仅需将以下行添加到您的 Podfile

pod 'BiometricAuthenticator'

对于 Swift 4.2 之前版本

pod 'BiometricAuthenticator', '~> 1.3.0'

作者

Chris Corea, [email protected]

许可

BiometricAuthenticator 在 MIT 许可下提供。更多信息请参阅 LICENSE 文件。