初始化 iOS 8
// 初始化 指纹识别 实例
LAContext *context = [LAContext new];
// 指纹错误 额外的提示按钮,对应下面的 kLAErrorUserFallback;为空时不显示
context.localizedFallbackTitle = @"";
// 检测是否有指纹识别
[context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]
typedef NS_ENUM(NSInteger, LAPolicy) {
LAPolicyDeviceOwnerAuthenticationWithBiometrics NS_ENUM_AVAILABLE(NA, 8_0) = kLAPolicyDeviceOwnerAuthenticationWithBiometrics,
LAPolicyDeviceOwnerAuthentication NS_ENUM_AVAILABLE(10_11, 9_0) = kLAPolicyDeviceOwnerAuthentication
};
// 指纹识别 识别回调
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:NSLocalizedString(@"使用指纹识别,进入下一步", nil)
reply:^(BOOL success, NSError *error) {
if (success) {
// 跳转
} else {
// 错误 error.code = ?
}
}];
// iOS 8
LAErrorAuthenticationFailed 身份验证失败 - 大于系统允许次数失败时
LAErrorUserCancel 用户取消
LAErrorUserFallback 用户失败后新增的按钮回调
LAErrorSystemCancel 系统取消,切换到系统外
LAErrorPasscodeNotSet 指纹ID未设置
LAErrorTouchIDNotAvailable 指纹ID不可用
LAErrorTouchIDNotEnrolled 指纹ID未登记
// iOS 9
LAErrorTouchIDLockout 指纹ID已锁
LAErrorAppCancel app取消
LAErrorInvalidContext 超时?
iOS9
涉及到 SecAccessControlRef 的安全库内容,暂无研究唉。
extern const NSTimeInterval LATouchIDAuthenticationMaximumAllowableReuseDuration NS_AVAILABLE_IOS(9_0);
- (void)invalidate NS_AVAILABLE(10_11, 9_0);
typedef NS_ENUM(NSInteger, LAAccessControlOperation) {
LAAccessControlOperationCreateItem,
LAAccessControlOperationUseItem,
LAAccessControlOperationCreateKey,
LAAccessControlOperationUseKeySign
} NS_ENUM_AVAILABLE(10_11, 9_0);
- (void)evaluateAccessControl:(SecAccessControlRef)accessControl
operation:(LAAccessControlOperation)operation
localizedReason:(NSString *)localizedReason
reply:(void(^)(BOOL success, NSError * __nullable error))reply
NS_AVAILABLE(10_11, 9_0);
@property (nonatomic, nullable, readonly) NSData *evaluatedPolicyDomainState NS_AVAILABLE(10_11, 9_0);
@property (nonatomic) NSTimeInterval touchIDAuthenticationAllowableReuseDuration NS_AVAILABLE_IOS(9_0);
1