IOS开发-指纹识别

来源:互联网 发布:windows caffe mnist 编辑:程序博客网 时间:2024/05/18 02:09

苹果系统自带指纹识别功能,只需要调用方法就可以实现指纹识别的功能

代码:

<span style="font-size:14px;"> if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {            NSLog(@"不支持");            return;        }        LAContext *ctx = [[LAContext alloc] init];        // 判断设备是否支持指纹识别        if ([ctx canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL]) {            NSLog(@"支持");            // 异步            // 提示:指纹识别只是判断当前用户是否是手机的主人。            [ctx evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"指纹登录" reply:^(BOOL success, NSError *error) {                if (success) {                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"指纹认证成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];                    [alert show];                }else if(error){                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"指纹认证失败" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];                    [alert show];                }            }];        } else {            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没有开启TOUCHID设备" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];            [alert show];        }</span>

只需要在方法中加入上面的代码,就可以直接调用,实现指纹认证

#import "LocalAuthentication/LAContext.h"

头文件导入不能忘了


0 0
原创粉丝点击