这是我的touchId函数代码。我希望让用户输入他们用来解锁手机的密码来验证他们的身份和登录,而无需输入用户名和密码。但是我只希望他们在触摸ID不起作用或不可用时使用此选项。
我将如何这样做?
@IBAction func touchIDLogin(sender: AnyObject) {
let authenticationContext = LAContext()
var error: NSError?
//check if device supports touch id, if not show error and stop
guard authenticationContext.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: &error) else{
displayAlert("TOUCH ID ERROR", msg: "This device does not support TouchID", option: false)
return
}
authenticationContext.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Verify who you are to login", reply: {[unowned self](success, error) -> Void in
if(success){
//Fingerprint recognized
var stored_pass = ""
var stored_user = ""
stored_pass = (self.my_keychain_wrapper.myObjectForKey("v_Data") as? String)!
stored_user = (NSUserDefaults.standardUserDefaults().valueForKey("username") as? String)!
if(!stored_pass.isEmpty || !stored_user.isEmpty){
PFUser.logInWithUsernameInBackground(stored_user, password: stored_pass, block: { (user, error) -> Void in
//unsuccessful login display error message
if user == nil {
if let error_string = error!.userInfo["error"] as? String{
self.displayAlert("ERROR IN LOGIN", msg: error_string, option: false)
}
}
//successful login
else{
self.performSegueWithIdentifier("dashboard_segue", sender: self)
}
})
}
else{
self.displayAlert("LOGIN ERROR", msg: "No valid login credentials were found", option: false)
}
}
//error check
else{
if let error = error{
let message = self.errorMessageForLAErrorCode(error.code)
self.displayAlert("TOUCH ID ERROR", msg: message, option: false)
}
}
})
}
答案 0 :(得分:0)
不幸的是,iOS没有提供验证系统密码输入的方法。
如果touchID失败,应用可能需要管理自己的密码。 This library允许应用管理带有UI的密码,就像系统用户界面一样,您可以鼓励用户将应用密码设置为系统密码。