对于Objective-C而言,只要几行代码即可搞定。

比如:

#import <LocalAuthentication/LocalAuthentication.h>

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    LAContext *context = [[LAContext alloc] init];
    if(![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil])
        NSLog(@"Touch ID not supported!");
    
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"找回密码" reply:^void(BOOL success, NSError *error){
        NSLog(@"Is success? %d", success);
        if(!success)
        {
            switch(error.code) {
                case LAErrorAuthenticationFailed:
                    NSLog(@"Authentication Failed");
                    break;
                    
                case LAErrorUserCancel:
                    NSLog(@"User Cancelled");
                    break;
                    
                case LAErrorUserFallback:
                    NSLog(@"User Fallback");
                    break;
                    
                case LAErrorSystemCancel:
                    NSLog(@"System Cancelled");
                    break;
                    
                case LAErrorPasscodeNotSet:
                    NSLog(@"Passcode Not Set");
                    break;
                    
                case LAErrorTouchIDNotAvailable:
                    NSLog(@"Touch ID Not Available");
                    break;
                    
                default:
                    break;
            }
        }
    }];
}

 

相关文章:

  • 2021-07-09
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
  • 2023-03-15
猜你喜欢
  • 2021-11-28
  • 2021-11-08
  • 2021-04-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案