每当用户关闭应用程序时,使用人脸ID

时间:2018-07-29 19:06:42

标签: ios swift telegram touch-id face-id

我正在尝试快速学习,最近我已经学会了如何将faceID添加到我的应用程序中,但是我想走得更远!有时,用户将应用程序最小化,并且可以在任何视图控制器中使用!并且我想在用户开始使用该应用程序时使用faceID。当faceID授予该用户时,它显示了他/她离开的vc!我需要像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)
                    }
            }

        })


    }

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

1 个答案:

答案 0 :(得分:3)

将与LAContext相关的代码放在应用程序委托的函数中。然后从didFinishLaunchingWithOptionsapplicationWillEnterForeground调用该函数。