Face ID evaluation process not working properly

后端 未结 2 697
逝去的感伤
逝去的感伤 2020-12-16 20:21

I\'m trying to get if Face ID or Touch ID succeeded in the function below

func authenticate() -> Bool{

    let context = LAContext()
    var error: NSErr         


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-16 21:05

    You should use a closure to obtain results of evaluation. Note that the return value for canEvaluatePolicy is a Bool but there is no return value for evaluatePolicy as it accepts a closure.

    You can modify your method to include a closure instead of return.

    func authenticate(completion: ((Bool) -> ())) {
        ...
        completion(true) // false if it failed.
        ...
    }
    

    In other parts of your app, where you earlier used a return value you would now have to use a closure like:

    class Foo {
       func test() {
           let isEvaluated = self.authenticate() // Old way
           self.authenticate { success in
               // bool will now indicate whether evaluation was done successfully or not.
           }
       }
    }
    

提交回复
热议问题