我们可以在模拟器中测试Face ID吗?

tec*_*erd 31 simulator biometrics ios iphone-x face-id

我们可以使用模拟器测试生物识别身份验证吗?

iPhone X Simulator显示面部ID注册菜单,但启用后,我该怎么办?

如何识别面部进行身份验证?

iPhone X Simulator  - 面部识别设置

Kru*_*nal 27

模拟器无法识别面部,但允许您模拟匹配和不匹配的面,如果您已启用Enrolled选项Face ID.


将以下代码添加到视图控制器并尝试使用Face-ID

import LocalAuthentication

class ViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
        localAuthentication()
    }



    func localAuthentication() -> Void {

        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, *) {
                if (laContext.biometryType == LABiometryType.faceID) {
                    localizedReason = "Unlock using Face ID"
                    print("FaceId support")
                } else if (laContext.biometryType == LABiometryType.touchID) {
                    localizedReason = "Unlock using Touch ID"
                    print("TouchId support")
                } else {
                    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")
                        }
                    }

                })
            })
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

FaceID身份验证将提示您第一次为您的应用程序允许FaceID检测.

在此输入图像描述


现在启用Face ID注册并运行您的应用以测试Face ID模拟测试.

这是匹配和不匹配面的模拟结果.

匹配面的结果:

在此输入图像描述


不匹配面的结果:

在此输入图像描述



Tam*_*gel 7

模拟器只是模拟正确和失败的面部识别的结果,就像使用Touch ID一样.它不识别面孔.