Reputation: 303
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:
reasonTextField
) is for users to input the reason.passwordTextField
) is for the account password.I've tried the following solutions without success:
textContentType
to .none
for the reasonTextField
.passwordTextField
has textContentType
set to .password
.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!
Upvotes: 0
Views: 56
Reputation: 11
Try this instead of it.
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 = .oneTimeCode // Use a more neutral type instead of .none
reasonTextField.autocorrectionType = .no
reasonTextField.spellCheckingType = .no
reasonTextField.smartDashesType = .no
reasonTextField.smartInsertDeleteType = .no
reasonTextField.smartQuotesType = .no
reasonTextField.accessibilityIdentifier = "reasonTextField"
passwordTextField.textContentType = .password
passwordTextField.autocorrectionType = .no
passwordTextField.spellCheckingType = .no
passwordTextField.isSecureTextEntry = true
passwordTextField.accessibilityIdentifier = "passwordTextField"
}
}
Using .oneTimeCode
is better than .none
.
Upvotes: 1