AutoFill OTP in iOS12 new feature (iOS12).

So, finally Apple integrated autofill OTP in iOS 12…kudos to Apple. Because now a days many sites and apps required to confirm login with security code via text message. 

Prior to iOS 12 it was little difficult for the user to enter the OTP as user had to toggle from OTP verification page to either messenger or Notification Centre.Then remember the entire OTP and type it back in the OTP verification page, which was really not a good user experience and consumes time.

With iOS 12, you no longer have to jump from the verification page to Messages to retrieve your security code. Instead, iOS will present the security code as an auto-fill option.

In iOS 12, when you receive an SMS message with an OTP or a verification code, the OS suggests the OTP in the keyboard’s quick type field. If your keyboard is present/on then at the top of the keyboard the OTP will display and just you have to press the OTP and it will fill in the textfield with the OTP automatically..its so cool πŸ˜±πŸ‘!! Check the image below how it looks.



I came across this after updating my iPhone 7 (Yes I have iPhone 😊) to iOS 12, and was verifying some login with OTP, I found this very useful and handy.

The feature is turned on by default, so you don’t really have to do anything to get it to work, which is a great way to make sure everyone uses it.

How Apple describes the feature:

SMS one-time passcodes will appear automatically as AutoFill suggestions, so you never have to worry about quickly memorizing them or typing them again.

So now let’s check how to implement it in your App (works on Xcode 10+)

To use this feature in app, you need to change UITextField of OTP’s textContentType to .oneTimeCode, example below

yourOtpTextField.textContentType = .oneTimeCode

This can also be done using Storyboard.

Select UITextField in storyboard/XIB click Click on Attribute inspector. Go to text input trait, click to Content type and select one time code and done.

Still (with autofill OTP) you can listen to the UITextField’s editingChanged event and customize your implementation.

NOTE: 
Security code only work with System keyboard. So avoid using custom keyboard.

Please leave your comments !!
Any suggestion or topic you want please comment !!

Comments

  1. Nice article! However the only disadvantage is we can't use autofill password feature, if we set the contentType to oneTimePassword.

    ReplyDelete

Post a Comment

Popular posts from this blog

Let’s understand what is optional in Swift and how to use !!

What is method chaining ?