iOS touchID和faceID判断

typedef NS_ENUM(NSInteger, LAContextSupportType) {
    LAContextSupportTypeNone,              // 不支持指纹或者faceID
    LAContextSupportTypeTouchID,           // 指纹识别
    LAContextSupportTypeFaceID,            // faceid
    LAContextSupportTypeTouchIDNotEnrolled,      // 支持指纹没有设置指纹
    LAContextSupportTypeFaceIDNotEnrolled        // 支持faceid没有设置faceid
};
#import 

+ (LAContextSupportType)getBiometryType {
    LAContext *context = [LAContext new];
    NSError *error = nil;
    BOOL supportEvaluatePolicy = [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];

    //    LAPolicyDeviceOwnerAuthenticationWithBiometrics iOS8.0以上支持,只有指纹验证功能
    //    LAPolicyDeviceOwnerAuthentication iOS 9.0以上支持,包含指纹验证与输入密码的验证方式
    LAContextSupportType type = LAContextSupportTypeNone;
    if (@available(iOS 11.0, *)) {
        if (context.biometryType == LABiometryTypeTouchID) {
            // 指纹
            if (error) {
                type = LAContextSupportTypeTouchIDNotEnrolled;
            } else {
                type = LAContextSupportTypeTouchID;
            }
        }else if (context.biometryType == LABiometryTypeFaceID) {
            // 面容
            if (error) {
                type = LAContextSupportTypeFaceIDNotEnrolled;
            } else {
                type = LAContextSupportTypeFaceID;
            }
        }else {
            // 不支持
        }
    } else {
        if (error) {
            if (error.code == LAErrorTouchIDNotEnrolled) {
                // 支持指纹但没有设置
                type = LAContextSupportTypeTouchIDNotEnrolled;
            }
        } else {
            type = LAContextSupportTypeTouchID;
        }
    }
#ifdef DEBUG
    NSArray *testArr = @[@"不支持指纹face",@"指纹录入",@"faceid录入",@"指纹未录入",@"faceID未录入"];
    NSInteger index = (NSInteger)type;
    NSLog(@"%@===xxx===%d=====%@",testArr[index],supportEvaluatePolicy,error);
#endif
    return type;
}

你可能感兴趣的:(iOS touchID和faceID判断)