每当用户关闭应用程序时使用面部 ID

using face Id whenever user close the app

我正在努力学习 swift,最近我学会了如何将 faceID 添加到我的应用程序中,但我想更进一步!有时用户最小化应用程序,它可能在任何视图控制器中!我想在用户开始使用 app.and 时使用 faceID,当 faceID 授予用户时,它显示 vc he/she 离开了!我需要 Telegram Messenger 之类的东西。

        let AUth = LAContext()
    var autherror:NSError?
    AUth.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &autherror)
    // Do any additional setup after loading the view.
    if autherror != nil
    {
        // there is an error : not available
        print("auth is not available on the ios")
    }
    else
    {
        // auth is available
        AUth.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Page contain SENSETIVE content, use your biometric ID to unlock the page.", reply: { ( complete:Bool! , error:Error!) ->Void in
            if error != nil
            {
                //there is an error
                print(error.localizedDescription)
            }
            else{
                //all set
                if complete == true
                {
                    print("auth successful")
                    // is auth success , goes to next page
                    let next = self.storyboard?.instantiateViewController(withIdentifier: "FirstviewPage") as! UITabBarController
                    self.present(next, animated: true, completion: nil)
                }
                else
                     {
                    //user was not the correct user
                    print("auth failed")
                    //we have an error
                    print(autherror?.localizedDescription ?? "...")
                    //show the normal screen
                    AUth.canEvaluatePolicy(LAPolicy.deviceOwnerAuthentication, error: &autherror)
                    }
            }

        })


    }

正如您在这里看到的那样,当用户打开应用程序时,它会检查此人是否是正确的人,但即使用户最小化应用程序并再次打开它,我也想要此功能

将您的 LAContext 相关代码放入您的应用委托的函数中。然后从 didFinishLaunchingWithOptionsapplicationWillEnterForeground.

调用该函数