BiometricAuthenticationFacade 1.0.4

BiometricAuthenticationFacade 1.0.4

测试经测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2016年10月

Vladimir Popko维护。



  • 作者
  • Visput

VPBiometricAuthenticationFacade v1.0.4

VPBiometricAuthenticationFacade是一个针对LocalAuthentication框架的高级包装器,它通过评估生物识别策略(触摸ID)来提供启用、禁用并授予应用功能访问权限的能力。

项目的完整描述在这里(俄语)可供参考http://habrahabr.ru/post/235699/

安装

拖放
  1. 将BiometricAuthenticationFacade.xcodeproj拖放到您的项目中;
  2. 将BiometricAuthenticationFacade添加到构建阶段 -> 目标依赖;
  3. 将BiometricAuthenticationFacade.framework添加到构建阶段 -> 与库链接;
  4. 将LocalAuthentication标准框架添加到您的项目中。

使用

导入框架头
#import <BiometricAuthenticationFacade/VPBiometricAuthenticationFacade.h>
创建对象实例
VPBiometricAuthenticationFacade *biometricFacade = [[VPBiometricAuthenticationFacade alloc] init];
检查当前设备上是否支持生物识别认证
if (biometricFacade.isAuthenticationAvailable) {
    // Authentication available
}
检查特定功能的认证是否已启用
if ([biometricFacade isAuthenticationEnabledForFeature:@"My secure feature"]) {
    // Authentication enabled
}
启用特定功能的认证
[biometricFacade enableAuthenticationForFeature:@"My secure feature" succesBlock:^{
    // Authentication enabled
} failureBlock:^(NSError *error) {
    // Failed to enable authentication
}];

如果当前设备不支持生物识别认证,则方法调用将失败。错误代码 kVPBiometricsUnavailabilityErrorCode

禁用特定功能的认证
[biometricFacade disableAuthenticationForFeature:@"My secure feature" withReason:@"Authentication reason" succesBlock:^{
    // Authentication disabled
} failureBlock:^(NSError *error) {
    // Failed to disable authentication
}];

"原因"参数是应用提供的请求认证的原因。此字符串应使用用户的当前语言提供,应简短、清晰。它将显示在认证对话框的副标题中。

执行此方法会导致显示系统认证对话框。
以下情况下方法调用将失败:
1. 如果当前设备上不可用生物识别认证。错误代码:kVPBiometricsUnavailabilityErrorCode
2. 如果用户取消认证。错误代码:kLAErrorUserCancel
3. 如果用户未能通过认证。错误代码:kLAErrorAuthenticationFailed
4. 如果用户点击了备用按钮(输入密码)。错误代码:kLAErrorUserFallback
5. 如果其他应用程序进入前台。错误代码:kLAErrorSystemCancel

针对特定功能的认证
[biometricFacade authenticateForAccessToFeature:@"My secure feature" withReason:@"Authentication reason" succesBlock:^{
    // Access granted
} failureBlock:^(NSError *error) {
    // Access denied
}];

执行此方法会导致显示系统认证对话框。
参见之前的方法描述,了解“reason”参数和在failureBlock中可能的错误代码。

注意
  1. 所有方法的block都在主线程上调用;
  2. LocalAuthentication框架的内部实现使用大约15分钟的缓存时间。这意味着如果您成功通过生物识别认证,然后将在短时间内尝试重复此过程,则系统不会显示认证对话框,它将立即允许访问。如果您需要避免缓存时间的行为,您必须为每次尝试通过认证使用新的VPBiometricAuthenticationFacade实例。

系统要求

它需要使用iOS SDK 8.0和更高版本构建。然而,它可以与低于目标版本的应用程序集成。

许可证

VPBiometricAuthenticationFacade是在MIT许可证下发布的。有关详细信息,请参阅LICENSE。