【问题标题】:using face Id whenever user close the app每当用户关闭应用程序时使用人脸 ID
【发布时间】:2018-07-29 19:06:42
【问题描述】:

我正在努力学习 swift,最近我学会了如何将 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)
                    }
            }

        })


    }

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 澄清一下,我必须在委托中为 lacontext 创建一个函数,然后在您提到的这两部分中调用它?
    猜你喜欢
    • 2012-05-16
    • 1970-01-01
    • 2021-12-27
    • 2023-03-22
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    相关资源
    最近更新 更多