How to AutoFill One Time Security Code (iOS 12 )?

Apple outlined many of the top iOS 12 features on WWDC 18. One of those is long waited features is security code auto fill.

As many site required to confirm login with a security code via text messages. And user have to toggle through from login page to messenger. And remember complete OTP(one time password) and type it back in login page. Which ultimately consumes time and gives bad user experience.

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

yourOtpTextField.textContentType = .oneTimeCode

This can also been achieve via 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.

  • Security code is only work with System keyboard. So avoid using custom keyboard.
  • Make sure otp message phrase has “code” or “passcode” and message is copyable.