我正在尝试快速学习,最近我学会了如何将 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)
}
}
})
}
正如您在此处看到的,当用户打开应用程序时,它会检查此人是否是正确的人,但即使用户最小化应用程序并再次打开它,我也想要此功能