iOS – Face ID生物识别集成

我为我的应用程序集成/实现了面部识别(本地身份validation)身份validation,除了面部识别提示警报窗口界面外,每件事情都运行良好。

它显示了一个圆角正方形,浅灰色背景和标题“面部ID”

应该为标题上方的空白区域设置什么。 这是脸部ID图标的空间吗? 如果是,那我该怎么设置呢? 我已经尝试了LAContext和LAPolicy中的所有内容。

看看这个快照:

在此处输入图像描述

这是我的代码:

let laContext = LAContext() var error: NSError? let biometricsPolicy = LAPolicy.deviceOwnerAuthenticationWithBiometrics if (laContext.canEvaluatePolicy(biometricsPolicy, error: &error)) { if let laError = error { print("laError - \(laError)") return } var localizedReason = "Unlock device" if #available(iOS 11.0, *) { switch laContext.biometryType { case .faceID: localizedReason = "Unlock using Face ID"; print("FaceId support") case .touchID: localizedReason = "Unlock using Touch ID"; print("TouchId support") case .none: print("No Biometric support") } } else { // Fallback on earlier versions } laContext.evaluatePolicy(biometricsPolicy, localizedReason: localizedReason, reply: { (isSuccess, error) in DispatchQueue.main.async(execute: { if let laError = error { print("laError - \(laError)") } else { if isSuccess { print("sucess") } else { print("failure") } } }) }) } 

这只发生在模拟器中,在实际设备中canvas被面部图标动画占用。

localizedReason仅适用于Touch ID,因为它们共享相同的API。

更新1:添加了屏幕录制:

  • iPhone X: https : //youtu.be/lklRnLNHyQk
  • iPhone 7: https : //youtu.be/iIcduvD5JO0
  • iPhone X Simulator: https : //youtu.be/bOlRVLIND5c

他们都运行相同的代码:

 func beginFaceID() { guard #available(iOS 8.0, *) else { return print("Not supported") } let context = LAContext() var error: NSError? guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else { return print(error) } let reason = "Face ID authentication" context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { isAuthorized, error in guard isAuthorized == true else { return print(error) } print("success") } } 

以下是TouchID和FaceID的工作代码以及所有错误代码(Swift 4)

https://stackoverflow.com/a/52093551/10150796