代码之家  ›  专栏  ›  技术社区  ›  Mythics Winter

一些iPad设备返回的生物识别码不适用于此代码,为什么?

  •  4
  • Mythics Winter  · 技术社区  · 6 年前

    我在理解返回值时遇到了一些问题,即使是一个只有以下代码的新项目。

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        LAContext*   touchContext          = [LAContext new];
        NSError*     policyEvaluationError = nil;
    
        [touchContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                                                error:&policyEvaluationError];
    
        NSLog(@"\n\n %@", policyEvaluationError);
    }
    

    这些都是iPad模拟器iOS 10.3.1-11.3上的结果。

    iPad(第五代)-“此设备上不提供生物测量。”

    iPad Air-“此设备上没有生物测量功能。”

    iPad Air 2-未注册任何身份。“”

    iPad Pro(9.7英寸)-“此设备上没有生物测量功能。”

    iPad Pro(12.9英寸)(第二代)-“此设备上没有生物测量功能。”

    这些“生物测量”的结果在此设备上不可用在注册或未注册这些设备时发生。

    所有测试的iPhone设备类型也返回“未注册任何身份”比如iPad Air 2,我希望他们没有注册,但拥有touchID硬件。注册时,根本没有错误。

    在一些实际的iPad设备上,结果似乎也有所不同,但方式不同。如果没有存储指纹,一些设备会返回“此设备上没有生物测量”而其他人只返回已注册/无。有了指纹,他们的行为似乎都和我想象的一样。

    据我所知,我们在生产中使用此代码已经有一段时间了,没有与此主题相关的投诉,但我们最近才在开发/QA中注意到它。

    这段代码是不是在所有设备上都不可靠,是否有什么可能发生了变化,还是我在这里做错了什么?

    1 回复  |  直到 4 年前
        1
  •  2
  •   saagarjha    6 年前

    这是苹果框架中的一个bug,我已经提交了rdar://problem/46148637为此。如果你感到好奇,以下是该报告的全文:

    iPad Pro (12.9-inch) (2nd generation) simulator thinks it doesn't have Touch ID
    
    Summary:
    LAContext().canEvaluatePolicy(_:error:) with the policy LAPolicy.deviceOwnerAuthenticationWithBiometrics fails with LAError.Code. biometryNotAvailable on the iPad Pro (12.9-inch) (2nd generation) simulator. A bit of digging suggests that:
    
    • LAContext().canEvaluatePolicy(_:error:), from LocalAuthentication.framework, ends up communicating with coreauthd to evaluate the policy.
    • The specific error is generated in -[BiometryHelper deviceHasBiometryWithError:] in DaemonUtils.framework, which is loaded into coreauthd.
    • -[BiometryHelper deviceHasBiometryWithError:] returns this error when -BiometryHelper._device is nil.
    • BiometryHelper._device is the first object grabbed from +[BKDeviceManager availableDevices], in BiometricKit.framework.
    • +[BKDeviceManager availableDevices] *should* create a Touch ID device descriptor if it finds that the device supports Touch ID, which it checks by calling MGGetBoolAnswer(@"touch-id").
    • MGGetBoolAnswer(@"touch-id") returns NO (!)
    • The device believes it does not have a Touch ID sensor.
    • LAContext().canEvaluatePolicy(_:error:) returns false because it believes the device cannot evaluate this policy.
    
    Steps to Reproduce:
    1. Try to evaluate a biometric policy on the  iPad Pro (12.9-inch) (2nd generation) simulator.
    
    Expected Results:
    I either receive a success, or something about being unenrolled.
    
    Actual Results:
    I'm told that this iPad doesn't have a Touch ID sensor, when clearly should have one.
    
    Version/Build:
    Xcode Version 10.1 (10B61)
    
    Configuration:
    Xcode Version 10.1 (10B61)/macOS Mojave 10.14.2 Beta (18C48a)