我想知道如何检查Touch ID的状态。 细节:如果触摸ID失败超过三次,则触摸ID将被禁用。要激活,我必须在锁定屏幕上输入密码或按ID菜单上的密码。我如何知道触摸ID的状态是能够还是禁用?
答案 0 :(得分:0)
// Create LA Context
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"Specify why you need TouchID";
// Policy evalivation - start
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
// Reply block - start
reply:^(BOOL success, NSError *error) {
// success - start
if (success) {
NSLog(@"User authenticated successfully, take appropriate action");
double delayInSeconds = 0.1;
dispatch_time_t replaceTab = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(replaceTab, dispatch_get_main_queue(), ^(void){
[self touchIDSuccess];
});
// success - end
// Not successful - start
} else {
// error != NULL - start
if(error != NULL)
{
// switch - start
switch (error.code){
case LAErrorUserCancel:
NSLog(@"LAErrorUserCancel");
break;
case LAErrorUserFallback:
NSLog(@"LAErrorUserFallback");
break;
case LAErrorAppCancel:
NSLog(@"LAErrorAppCancel");
break;
case LAErrorAuthenticationFailed:
NSLog(@"kLAErrorAuthenticationFailed");
default:
break;
}// switch - end
}// error != NULL - end
}// Not success - end
}];// Reply block - end
} else {
// Touch ID was previously used but now Could not evaluate policy , may be because user removed the fingerprint
NSLog(@"Could not evaluate policy");
}