我目前在我的应用中有touchID,目前它正常运行。每次登录" touchID激活"它都会有点烦人。警报弹出。有没有办法改变它,所以它只在第一次登录而不是再次弹出?这是我的触摸ID代码,我在登录屏幕的viewDidLoad中调用checkIfTouchIDActivated():
// MARK: TouchID
//Create a authentication context
let authenticationContext = LAContext()
var error:NSError?
//Check if the device has a fingerprint sensor, if not, dismiss
func checkIfTouchIDActivated () {
guard authenticationContext.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: &error) else {
print("TouchID not detected")
return
}
print("TouchID detected")
//Check the fingerprint
authenticationContext.evaluatePolicy(
.DeviceOwnerAuthenticationWithBiometrics,
localizedReason: "TouchID activated",
reply: { [unowned self] (success, error) -> Void in
//fingerprint has been recognized
if( success ){
self.loginButtonPressed(self)
}else {
// Check if there is an error
if let error = error {
let message = self.touchID.errorMessageForLAErrorCode(error.code)
self.showAlertViewAfterEvaluatingPolicyWithMessage(message)
}
}
})
}
答案 0 :(得分:0)
您已将"TouchID activated"
作为localizedReason
。如果您不想向用户显示您要为其验证身份的原因,请提供""
。它通常类似于"Are you the device owner?"
或"Sign in with your touch-ID"
,表明您向用户请求touch-id
身份验证的原因。