在iOS 9.x中,经过5次(3次2次)尝试生物识别登录后,iOS会自动弹出默认的PIN码屏幕。这在iOS 10 Beta中不会发生。它只是失败了" canEvaluatePolicy"检查一下。有谁知道这只是iOS 10 Beta中的一个错误,还是我必须添加代码来支持pin代码屏幕?
以下是代码:
-(void)touchTester {
LAContext *myContext = [[[LAContext alloc] init] autorelease];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"Sign on with TouchID\u00AE or enter password.";
myContext.localizedFallbackTitle = @"Enter Password";
self.touchIdActive = NO;
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
self.touchIdActive = YES;
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Launching loginUser");
[self loginUser:YES];
});
} else {
self.touchIdActive = NO;
NSString * errMsg = error.localizedDescription;
if (![errMsg isEqualToString:@"Canceled by user."]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:errMsg
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alertView show];
});
}
}
}];
} else {
// This is where we go after lockout in iOS 10
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:authError.localizedDescription
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alertView show];
});
}
}
答案 0 :(得分:3)
显示代码:
LAContext *myContext = [[LAContext alloc] init];
myContext.localizedFallbackTitle = [InternationalControl localStringByKey:@"gesture_forget"];
NSError *authError = nil;
NSString *myLocalizedReasonString = [InternationalControl localStringByKey:@"touchHome"];
BOOL isOK = [myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError];
if (isOK) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
NSLog(@" 查看是什么情况 %@",error);
TouchType typeState = TouchTypeOther;
if (success) {
NSLog(@"解锁成功");
} else {
if(error.code == -8){
dispatch_async(dispatch_get_main_queue(), ^{
LAContext *myContext = [[LAContext alloc] init];
myContext.localizedFallbackTitle = [InternationalControl localStringByKey:@"gesture_forget"];
NSError *authError = nil;
NSString *myLocalizedReasonString = [InternationalControl localStringByKey:@"touchHome"];
BOOL isOK = [myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&authError];
if (isOK) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
NSLog(@" 查看是什么情况 %@",error);
}];
}
});
}
}
}];
} else {
if(authError.code == -8){
dispatch_async(dispatch_get_main_queue(), ^{
LAContext *myContext = [[LAContext alloc] init];
myContext.localizedFallbackTitle = [InternationalControl localStringByKey:@"gesture_forget"];
NSError *authError = nil;
NSString *myLocalizedReasonString = [InternationalControl localStringByKey:@"touchHome"];
BOOL isOK = [myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&authError];
if (isOK) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
NSLog(@" 查看是什么情况 %@",error);
}];
}
});
}
NSLog(@"%@",authError);
}