iOS8.0如何使用Touch ID来做验证

对于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;
            }
        }
    }];
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。