繁体   English   中英

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

[英]Can we test Face ID in simulator?

我们可以使用模拟器测试生物认证吗?

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

它将如何识别人脸进行身份验证?

iPhone X 模拟器 - 面容 ID 设置

Simulator 无法识别人脸,但允许您模拟匹配和不匹配的人脸, Enrolled是您已从Face ID启用Enrolled选项。


将以下代码添加到您的视图控制器并尝试使用 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")
                        }
                    }

                })
            })
        }


    }
}

FaceID 身份验证将首次提示您允许对您的应用进行 FaceID 检测。

在此处输入图片说明


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

这是匹配和非匹配人脸的模拟结果。

人脸匹配结果:

在此处输入图片说明


不匹配人脸的结果:

在此处输入图片说明


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

正如你所问,但启用后,我能做什么?

就像触摸 ID 注册一样,您可以在 iPhone-X 上使用 face-Id 验证事物。 但是模拟器有一些限制,如 Appstore 等。通过 face-Id 注册,您可以执行以下操作 -

  • 使用面容 ID 进行购买。
  • 使用面容 ID 登录(登录应用)。
  • 在 Safari 中自动填充密码。
  • 在 iTunes Store、App Store 和 iBooks Store 中。

在 Apple 查看更多

与@krunal 给出的相同,如果应该在第一之外,则为第二。

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)) {



        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")
                    }
                }
            })
        })
    }
//This should be outside of if

 if let laError = error {
        print("laError - \(laError)")
        return
     }
 }
}

看到这篇文章。 您可以在 UITests 文件夹中创建 Biometrics.m、Biometrics.h 和 bridging-header.h 文件,并更新您的 UI 测试目标以使用该桥接头。 https://github.com/KaneCheshire/BiometricAutomationDemo

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM