How to auto fetch OTP, if we use multiple text fields
up vote
0
down vote
favorite
I know that if we want to auto fetch the OTP(if we use single textfield) we need to use
otpTextField.textContentType = .oneTimeCode
But, If we use multiple textfield(According to following image)
how should we achieve this ?
ios swift uitextfield one-time-password
add a comment |
up vote
0
down vote
favorite
I know that if we want to auto fetch the OTP(if we use single textfield) we need to use
otpTextField.textContentType = .oneTimeCode
But, If we use multiple textfield(According to following image)
how should we achieve this ?
ios swift uitextfield one-time-password
Please be more precise. Are you stuck at designing the UI or you stuck at coding part ?
– Teja Nandamuri
Nov 21 at 13:52
1
Make a custom classUITextField
that will have custom bottom drawing border and you good to go! No need to have 4 textfields.
– inokey
Nov 21 at 13:52
@TejaNandamuri, i was stuck at coding part. I want to auto fetch the OTP
– amma teja
Nov 22 at 5:35
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I know that if we want to auto fetch the OTP(if we use single textfield) we need to use
otpTextField.textContentType = .oneTimeCode
But, If we use multiple textfield(According to following image)
how should we achieve this ?
ios swift uitextfield one-time-password
I know that if we want to auto fetch the OTP(if we use single textfield) we need to use
otpTextField.textContentType = .oneTimeCode
But, If we use multiple textfield(According to following image)
how should we achieve this ?
ios swift uitextfield one-time-password
ios swift uitextfield one-time-password
edited Nov 22 at 4:44
Steve Vinoski
16.2k32133
16.2k32133
asked Nov 21 at 13:41
amma teja
8919
8919
Please be more precise. Are you stuck at designing the UI or you stuck at coding part ?
– Teja Nandamuri
Nov 21 at 13:52
1
Make a custom classUITextField
that will have custom bottom drawing border and you good to go! No need to have 4 textfields.
– inokey
Nov 21 at 13:52
@TejaNandamuri, i was stuck at coding part. I want to auto fetch the OTP
– amma teja
Nov 22 at 5:35
add a comment |
Please be more precise. Are you stuck at designing the UI or you stuck at coding part ?
– Teja Nandamuri
Nov 21 at 13:52
1
Make a custom classUITextField
that will have custom bottom drawing border and you good to go! No need to have 4 textfields.
– inokey
Nov 21 at 13:52
@TejaNandamuri, i was stuck at coding part. I want to auto fetch the OTP
– amma teja
Nov 22 at 5:35
Please be more precise. Are you stuck at designing the UI or you stuck at coding part ?
– Teja Nandamuri
Nov 21 at 13:52
Please be more precise. Are you stuck at designing the UI or you stuck at coding part ?
– Teja Nandamuri
Nov 21 at 13:52
1
1
Make a custom class
UITextField
that will have custom bottom drawing border and you good to go! No need to have 4 textfields.– inokey
Nov 21 at 13:52
Make a custom class
UITextField
that will have custom bottom drawing border and you good to go! No need to have 4 textfields.– inokey
Nov 21 at 13:52
@TejaNandamuri, i was stuck at coding part. I want to auto fetch the OTP
– amma teja
Nov 22 at 5:35
@TejaNandamuri, i was stuck at coding part. I want to auto fetch the OTP
– amma teja
Nov 22 at 5:35
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
If you can get the auto OTP for single field, you can split that text into your four text fields. I believe.
You may have to use textField's change observer as like below,
textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
func textFieldDidChange(_ textField: UITextField) {
// here check you text field's input Type
if textField.textContentType == UITextContentType.oneTimeCode{
//here split the text to your four text fields
if let otpCode = textField.text, otpCode.count > 3{
textField.text = String(otpCode[otpCode.startIndex])
textField1.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 1)])
textField2.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 2)])
textField3.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 3)])
}
}
}
add a comment |
up vote
0
down vote
UPDATE iOS 12
Apple will allow the support to read One Time Code(OTP - One Time Password) which you will get in the iPhone device.
iOS supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInput protocol. System keyboard set the textContentType on it to .oneTimeCode
1) Using Code
singleFactorCodeTextField.textContentType = .oneTimeCode
2) Using Storyboard/XIB
Select UITextField/UITextView in storyboard/XIB click Click on Attribute inspector. Go to text input trait, click to Content type and select one time code and done.
The operating system will detect verification codes from Messages automatically with this UITextContentType set.
Also you can split for that otp what you expect.
Check out the official documentation for https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_a_text_input_view
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If you can get the auto OTP for single field, you can split that text into your four text fields. I believe.
You may have to use textField's change observer as like below,
textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
func textFieldDidChange(_ textField: UITextField) {
// here check you text field's input Type
if textField.textContentType == UITextContentType.oneTimeCode{
//here split the text to your four text fields
if let otpCode = textField.text, otpCode.count > 3{
textField.text = String(otpCode[otpCode.startIndex])
textField1.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 1)])
textField2.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 2)])
textField3.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 3)])
}
}
}
add a comment |
up vote
0
down vote
If you can get the auto OTP for single field, you can split that text into your four text fields. I believe.
You may have to use textField's change observer as like below,
textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
func textFieldDidChange(_ textField: UITextField) {
// here check you text field's input Type
if textField.textContentType == UITextContentType.oneTimeCode{
//here split the text to your four text fields
if let otpCode = textField.text, otpCode.count > 3{
textField.text = String(otpCode[otpCode.startIndex])
textField1.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 1)])
textField2.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 2)])
textField3.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 3)])
}
}
}
add a comment |
up vote
0
down vote
up vote
0
down vote
If you can get the auto OTP for single field, you can split that text into your four text fields. I believe.
You may have to use textField's change observer as like below,
textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
func textFieldDidChange(_ textField: UITextField) {
// here check you text field's input Type
if textField.textContentType == UITextContentType.oneTimeCode{
//here split the text to your four text fields
if let otpCode = textField.text, otpCode.count > 3{
textField.text = String(otpCode[otpCode.startIndex])
textField1.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 1)])
textField2.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 2)])
textField3.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 3)])
}
}
}
If you can get the auto OTP for single field, you can split that text into your four text fields. I believe.
You may have to use textField's change observer as like below,
textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
func textFieldDidChange(_ textField: UITextField) {
// here check you text field's input Type
if textField.textContentType == UITextContentType.oneTimeCode{
//here split the text to your four text fields
if let otpCode = textField.text, otpCode.count > 3{
textField.text = String(otpCode[otpCode.startIndex])
textField1.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 1)])
textField2.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 2)])
textField3.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 3)])
}
}
}
edited Nov 22 at 15:08
rmaddy
237k27308374
237k27308374
answered Nov 21 at 14:31
Natarajan
2,00931024
2,00931024
add a comment |
add a comment |
up vote
0
down vote
UPDATE iOS 12
Apple will allow the support to read One Time Code(OTP - One Time Password) which you will get in the iPhone device.
iOS supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInput protocol. System keyboard set the textContentType on it to .oneTimeCode
1) Using Code
singleFactorCodeTextField.textContentType = .oneTimeCode
2) Using Storyboard/XIB
Select UITextField/UITextView in storyboard/XIB click Click on Attribute inspector. Go to text input trait, click to Content type and select one time code and done.
The operating system will detect verification codes from Messages automatically with this UITextContentType set.
Also you can split for that otp what you expect.
Check out the official documentation for https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_a_text_input_view
add a comment |
up vote
0
down vote
UPDATE iOS 12
Apple will allow the support to read One Time Code(OTP - One Time Password) which you will get in the iPhone device.
iOS supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInput protocol. System keyboard set the textContentType on it to .oneTimeCode
1) Using Code
singleFactorCodeTextField.textContentType = .oneTimeCode
2) Using Storyboard/XIB
Select UITextField/UITextView in storyboard/XIB click Click on Attribute inspector. Go to text input trait, click to Content type and select one time code and done.
The operating system will detect verification codes from Messages automatically with this UITextContentType set.
Also you can split for that otp what you expect.
Check out the official documentation for https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_a_text_input_view
add a comment |
up vote
0
down vote
up vote
0
down vote
UPDATE iOS 12
Apple will allow the support to read One Time Code(OTP - One Time Password) which you will get in the iPhone device.
iOS supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInput protocol. System keyboard set the textContentType on it to .oneTimeCode
1) Using Code
singleFactorCodeTextField.textContentType = .oneTimeCode
2) Using Storyboard/XIB
Select UITextField/UITextView in storyboard/XIB click Click on Attribute inspector. Go to text input trait, click to Content type and select one time code and done.
The operating system will detect verification codes from Messages automatically with this UITextContentType set.
Also you can split for that otp what you expect.
Check out the official documentation for https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_a_text_input_view
UPDATE iOS 12
Apple will allow the support to read One Time Code(OTP - One Time Password) which you will get in the iPhone device.
iOS supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInput protocol. System keyboard set the textContentType on it to .oneTimeCode
1) Using Code
singleFactorCodeTextField.textContentType = .oneTimeCode
2) Using Storyboard/XIB
Select UITextField/UITextView in storyboard/XIB click Click on Attribute inspector. Go to text input trait, click to Content type and select one time code and done.
The operating system will detect verification codes from Messages automatically with this UITextContentType set.
Also you can split for that otp what you expect.
Check out the official documentation for https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_a_text_input_view
answered Nov 23 at 7:22
Nagendran Arivalagan
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413385%2fhow-to-auto-fetch-otp-if-we-use-multiple-text-fields%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please be more precise. Are you stuck at designing the UI or you stuck at coding part ?
– Teja Nandamuri
Nov 21 at 13:52
1
Make a custom class
UITextField
that will have custom bottom drawing border and you good to go! No need to have 4 textfields.– inokey
Nov 21 at 13:52
@TejaNandamuri, i was stuck at coding part. I want to auto fetch the OTP
– amma teja
Nov 22 at 5:35