IOS iPhone X Face ID
好久没过来,小知识知识,预祝大家清明节快乐
iPhone X 已经出来一段时间了,虽然面部识别很高大上,但是小白我还是买不起啊,一直没有体会到那种装B的感觉,我看到支付宝,微信都用系统自带的Face ID进行支付认证,于是我就研究下了(借朋友的手机、可怜)
其实很简单基本和Tounch ID一个样子,不说没用的啦 直接上代码
记住要添加头文件
#import <LocalAuthentication/LocalAuthentication.h>
if (@available(iOS 8.0, *)) {
LAContext *context = [[LAContext alloc] init];
NSString *typeString = @"";
if (@available(iOS 11.0, *)) {
if (context.biometryType == LABiometryTypeTouchID) {
typeString = @"指纹登录";
}else if (context.biometryType == LABiometryTypeFaceID){
typeString = @"Face ID登录";
}
} else {
}
[self loginType:typeString withContent:context];
}else {
NSLog(@"你的设备不支持指纹识别");
}
- (void)loginType:(NSString *)type withContent:(LAContext *)context{
检验是否系统支持FaceID
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
验证FaceID是否通过
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:type reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
UIAlertController *con = [UIAlertController alertControllerWithTitle:@"提示" message:type preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *alt1 = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
}];
[con addAction:alt1];
[self presentViewController:con animated:YES completion:nil];
}else{
UIAlertController *con = [UIAlertController alertControllerWithTitle:@"提示" message:type preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *alt1 = [UIAlertAction actionWithTitle:@"失败" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
}];
[con addAction:alt1];
[self presentViewController:con animated:YES completion:nil];
}
}];
}
}