I’m encountering an issue with the autofill behavior in one of my iOS applications. On an action confirmation screen, users can enter a reason in the first text field and their account password in the second text field for validation purpose. However, when users use biometric authentication (Touch ID/Face ID) to autofill the password, the username from the keychain is mistakenly being entered into the reason text field (over-rides the already filled reason).
Here’s the setup:
- The first text field (
reasonTextField
) is for users to input the reason. - The second text field (
passwordTextField
) is for the account password.
I’ve tried the following solutions without success:
- Setting
textContentType
to.none
for thereasonTextField
. - Ensuring
passwordTextField
hastextContentType
set to.password
. - Using distinct accessibility identifiers for both text fields.
Here’s a simplified version of my code:
import UIKit
class ActionConfirmationViewController: UIViewController {
@IBOutlet weak var reasonTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
configureTextFields()
}
func configureTextFields() {
reasonTextField.textContentType = .none
reasonTextField.accessibilityIdentifier = "reasonTextField"
passwordTextField.textContentType = .password
passwordTextField.accessibilityIdentifier = "passwordTextField"
passwordTextField.isSecureTextEntry = true
}
}
Despite these measures, the issue persists. Has anyone experienced a similar problem or have any suggestions on how to prevent the username from being autofilled into the reason text field? Any help would be greatly appreciated!