Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift:&;生物识别:如何以布尔值形式获取身份验证结果_Ios_Swift_Authentication_Biometrics_Localauthentication - Fatal编程技术网

Ios Swift:&;生物识别:如何以布尔值形式获取身份验证结果

Ios Swift:&;生物识别:如何以布尔值形式获取身份验证结果,ios,swift,authentication,biometrics,localauthentication,Ios,Swift,Authentication,Biometrics,Localauthentication,我的主要目标是在我的react native项目中架起swift的桥梁。但让我们关注斯威夫特。 我想获得本地生物特征认证结果 生物特征 我已经设法让生物特征认证出现了。但我想得到的结果是布尔值——成功还是失败。 但是,我的函数无法返回正确的结果。请看一看 // Biometric Authentication func biometricAuthentication() -> Bool { print("In authenticateUser()"

我的主要目标是在我的react native项目中架起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
        }
    }

@瓦洛西普,让我们关注全局。这个小错误可以稍后修复。您知道如何将生物识别结果作为布尔值获取吗?生物识别身份验证是异步进行的,因为用户需要一些时间来响应提示。这意味着您不能返回布尔值。您需要提供一些闭包,一旦有了answer@Paulw11你能告诉我怎么做吗?我对ios开发人员还很陌生。搜索“[swift]return asynchronous”()你会看到很多这种模式的例子。完全正确。使用closure参数指定异步进程完成时应调用的内容。