ios - 用户拒绝使用时无法检查 Face ID

标签 ios touch-id face-id

如果设备支持Face IDTouch ID,我想对用户采取不同的操作。

当使用 Face ID 时,iOS 请求使用许可。 (与 Touch ID 不同)。

如果用户拒绝许可,context.biometryType 返回 LABiometryTypeNone。

有没有办法检查设备支持的Touch IDFace ID

LAContext *context = [[LAContext alloc] init];

NSError *error;

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {

}

if (@available(iOS 11.0, *)) {
    if (context.biometryType == LABiometryTypeFaceID) {
        // support FaceID 
    }
}

// support TouchID

控制台输出

(lldb) po error
Error Domain=com.apple.LocalAuthentication Code=-6 "User has denied the use of biometry for this app." UserInfo={NSLocalizedDescription=User has denied the use of biometry for this app.}

(lldb) po context.biometryType
LABiometryTypeNone

NOTE: I Don't want to use passcode authentication. I just need to know device is support Touch ID or Face ID

最佳答案

使用 LAContext 的属性 biometryType 检查和评估可用的生物识别策略。 (对于密码身份验证,当生物识别失败时,使用:LAPolicyDeviceOwnerAuthentication)

试试看:

LAContext *laContext = [[LAContext alloc] init];

NSError *error;


// For a passcode authentication , when biometric fails, use: LAPolicyDeviceOwnerAuthentication
//if ([laContext canEvaluatePolicy: LAPolicyDeviceOwnerAuthentication error:&error]) {
if ([laContext canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {    
    if (error != NULL) {
        // handle error
    } else {

        if (@available(iOS 11, *)) {
            if (laContext.biometryType == LABiometryTypeFaceID) {
                //localizedReason = "Unlock using Face ID"
                NSLog(@"FaceId support");
            } else if (laContext.biometryType == LABiometryTypeTouchID) {
                //localizedReason = "Unlock using Touch ID"
                NSLog(@"TouchId support");
            } else {
                //localizedReason = "Unlock using Application Passcode"
                NSLog(@"No biometric support or Denied biometric support");
            }
        } else {
            // Fallback on earlier versions
        }


        [laContext evaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"Test Reason" reply:^(BOOL success, NSError * _Nullable error) {

            if (error != NULL) {
                // handle error
            } else if (success) {
                // handle success response
            } else {
                // handle false response
            }
        }];
    }
}

关于ios - 用户拒绝使用时无法检查 Face ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48382721/

相关文章:

ios - 在 iOS 8.0 中使用数据库 Parse.com 登录用户的 TouchID

ios - 我可以在 CCAnimation 中使用 blendFunc 吗?

ios - 使用 Xcode 中另一个场景中的按钮暂停音乐

ios - Touch ID 与 Face ID 代码

ios - 什么是 NSFaceIDUsageDescription - Face ID Usage Description Info.plist key ?

ios - 如何以编程方式检查对 'Face Id' 和 'Touch Id' 的支持

ios - 如何检查我的应用程序是否启用了 Face id?

iphone - 如何访问 NSArray 中的某个值?

ios - 在没有黑色背景的情况下调整透明图像(UIImage)的大小

ios - 如何查看 TouchID 启用与否