简体   繁体   English

Xcode 模拟器不显示Face ID生物识别提示

[英]Xcode simulator does not show Face ID biometrics prompt

`Hi everyone, I am new to Swift and following a biometrics authentication tutorial to click a button and use Face ID or Touch ID. `大家好,我是 Swift 的新手,按照生物识别认证教程点击按钮并使用 Face ID 或 Touch ID。

Nothing happens when the biometric authentication button is pressed because canEvaluate etc do not get set to true.按下生物认证按钮时没有任何反应,因为 canEvaluate 等未设置为 true。 Details below.详情如下。

variables and the relevant function变量和相关的 function


    private(set) var context = LAContext()
    @Published private(set) var biometryType: LABiometryType = .none
    private(set) var canEvaluatePolicy = false 
    @Published private(set) var isAuthenticated = false`

    func getBiometryType(){
        context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
        biometryType = context.biometryType
    }



    func authenticatedWithBiometrics() async {
        context = LAContext() 
        
        print("inside auth func")
         
  
        
        if canEvaluatePolicy{
            let reason = "to log in to your account"
            
            do{

                let success = try await context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) 
             
                print(success)
                if success {
                    DispatchQueue.main.async {
                        self.isAuthenticated = true
                        print("is authenticated", self.isAuthenticated)
                    }
                }
            }
            catch{ //if fail to authenticate, throw an error, show it, no biometry
                
                print(error.localizedDescription)
                DispatchQueue.main.async {
                    self.errorDescription = error.localizedDescription
                    self.showAlert = true
                    self.biometryType = .none
                }
            }
        }
        
    }

The issue: nothing happens when I click on the button that calls authenticatedwithbiometrics().问题:当我单击调用 authenticatedwithbiometrics() 的按钮时,没有任何反应。 The function is called, the issue is that canEvaluatePolicy is FALSE and does not get set to true in getBiometryType.调用了 function,问题是 canEvaluatePolicy 为 FALSE,并且未在 getBiometryType 中设置为 true。 If I manually configure variables canEvaluatePolicy and success to true, we eventually run into the error.localizedDescription -> "biometry is not enrolled".如果我手动将变量 canEvaluatePolicy 和 success 配置为 true,我们最终会遇到 error.localizedDescription -> “biometry is not enrolled”。

I've tried different simulators: iPhone 13, 14, 14 Pro, 14Pro Max, and SE which uses TouchID, and that also does nothing.我尝试过不同的模拟器:iPhone 13、14、14 Pro、14Pro Max 和使用 TouchID 的 SE,但也没有任何作用。

I've seen someone who had a same problem, but then it was solved by trying different simulators.我见过有人有同样的问题,但后来通过尝试不同的模拟器解决了。 That did not solve my issue.那并没有解决我的问题。

I don't think it's an issue with the code because it's literally copied from a working tutorial.我不认为代码有问题,因为它实际上是从工作教程中复制的。 Do I need to configure something in the simulator?我需要在模拟器中配置一些东西吗?

Can we test Face ID in simulator? 我们可以在模拟器中测试 Face ID 吗? this type of answer is not useful to me because I cannot even evoke the gray popup that initiates the face or touch ID process.这种类型的答案对我没有用,因为我什至无法唤起启动面部或触摸 ID 过程的灰色弹出窗口。

I am using the newest version of xcode.我使用的是最新版本的 xcode。

Thank you.谢谢你。 ` `

I know why now.我现在知道为什么了。 You have to restart the build after checking the "Enrolled face" button for the cue to show up.选中“已登记面孔”按钮后,您必须重新开始构建才能显示提示。

You can used biometric authentication with simulator but you have to ensure you check enrolled in feature > FaceId > Enrolled after this you can check both scenarios Matching or Non Matching您可以使用模拟器使用生物识别身份验证,但您必须确保检查已注册功能 > FaceId > 在此之后您可以检查两种情况匹配或不匹配在此处输入图像描述

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

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