首页 > 解决方案 > Flutter、local_auth:Face ID 认证不起作用(即使可用)

问题描述

我需要在颤振应用程序中实现人脸 ID(生物识别)身份验证。我正在使用颤振包“local_auth”v1.1.6(https://pub.dev/packages/local_auth)。但是,当在所需设备上运行时,人脸验证选项在应用程序中不可用。

我正在使用以下功能,该功能在按下按钮时运行:

Future<bool> authenticate() async {
  try {
    final canCheckBiometrics = await _auth.canCheckBiometrics;
    print('canCheckBiometrics: ');
    print(canCheckBiometrics);

    final availableBiometrics = await _auth.getAvailableBiometrics();
    print('getAvailableBiometrics: ');
    print(availableBiometrics);

    return await _auth.authenticate(
      localizedReason: 'Authenticate',
      biometricOnly: true,
    );
  } on PlatformException catch (e) {
    print(e);
    rethrow;
  }

}

但是,面部身份验证永远不会显示为可用的身份验证选项,即使它被列为“可用的生物特征”:

I/flutter ( 4816): canCheckBiometrics:
I/flutter ( 4816): true
I/flutter ( 4816): getAvailableBiometrics:
I/flutter ( 4816): [BiometricType.fingerprint, BiometricType.face]

如果设备上同时设置了指纹和面部,则指纹显示为唯一可用的身份验证选项。如果只设置了 face,则 local_auth 库会抛出“NotEnrolled”异常(如果没有设置任何方法,则相同):

I/flutter ( 4816): canCheckBiometrics:
I/flutter ( 4816): true
I/flutter ( 4816): getAvailableBiometrics:
I/flutter ( 4816): [BiometricType.fingerprint, BiometricType.face]
I/flutter ( 4816): PlatformException(NotEnrolled, No biometrics enrolled on this device., null, null)

为了运行该应用程序,我使用的是搭载 Android 10 的 ULEFONE ARMOR X7 手机 - 它同时具有指纹和人脸 ID 身份验证功能,两者都可用于解锁设备屏幕 - 即使只设置了面部,它也可用于解锁屏幕,但它在应用程序中不可用。

有什么方法可以在这款手机上启用 Face ID 身份验证吗?对我来说,让它专门在这个设备上工作是很重要的。

标签: androidflutterbiometricsface-idlocalauthentication

解决方案


推荐阅读