Swift :& Biometric : 如何将身份验证结果获取为布尔值

问题描述

我的主要目标是在我的 React Native 项目中桥接 swift。但让我们专注于 Swift。 我想获取本地生物认证结果。

生物识别 我已经设法让生物识别身份验证出现。但我想将结果作为布尔值 - 成功或失败。 但是,我的函数无法返回正确的结果。请看一下

// Biometric Authentication
    func biometricAuthentication() -> Bool {
        print("In authenticateUser()")
        let context = LAContext()
        let reason = "Biometric Authntication testing !!"
        //        var authError: NSError?
        var result : Bool = false
        
        if #available(iOS 8.0,macOS 10.12.1,*){
            print("in available")
            context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics,localizedReason: reason) { (success,error) in
                
                
                
                dispatchQueue.main.async {
                    if success {
                        result = true
                        print("Success")
                    }else{
                        print("Failed")
                        return
                    }
                    //                    return result
                }
            }
            
            print("Result : \(result)")
            
            return result
            
        }else{
            print("This feature is not supported.")
            self.resultLabel.text = "Not Supported"
            return result
        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)