iOS touchID和faceID判斷

typedef NS_ENUM(NSInteger, LAContextSupportType) {
    LAContextSupportTypeNone,              // 不支持指紋或者faceID
    LAContextSupportTypeTouchID,           // 指紋識別
    LAContextSupportTypeFaceID,            // faceid
    LAContextSupportTypeTouchIDNotEnrolled,      // 支持指紋沒有設(shè)置指紋
    LAContextSupportTypeFaceIDNotEnrolled        // 支持faceid沒有設(shè)置faceid
};
#import <LocalAuthentication/LocalAuthentication.h>

+ (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) {
                // 支持指紋但沒有設(shè)置
                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;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容