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)



some thing like this



how should we achieve this ?










share|improve this question
























  • 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















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)



some thing like this



how should we achieve this ?










share|improve this question
























  • 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













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)



some thing like this



how should we achieve this ?










share|improve this question















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)



some thing like this



how should we achieve this ?







ios swift uitextfield one-time-password






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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
















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












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)])
}
}

}





share|improve this answer






























    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






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      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

























      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)])
      }
      }

      }





      share|improve this answer



























        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)])
        }
        }

        }





        share|improve this answer

























          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)])
          }
          }

          }





          share|improve this answer














          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)])
          }
          }

          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 at 15:08









          rmaddy

          237k27308374




          237k27308374










          answered Nov 21 at 14:31









          Natarajan

          2,00931024




          2,00931024
























              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






              share|improve this answer

























                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






                share|improve this answer























                  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






                  share|improve this answer












                  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







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 at 7:22









                  Nagendran Arivalagan

                  12




                  12






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      What visual should I use to simply compare current year value vs last year in Power BI desktop

                      Alexandru Averescu

                      Trompette piccolo