Skip to content

Instantly share code, notes, and snippets.

@MojtabaHs
Last active October 11, 2022 09:01
Show Gist options
  • Save MojtabaHs/8bb38158141e5b173ba18248ab69ddb8 to your computer and use it in GitHub Desktop.
Save MojtabaHs/8bb38158141e5b173ba18248ab69ddb8 to your computer and use it in GitHub Desktop.

Since iOS 12, the system can read the one-time password from the received SMS automatically and add it above the keyboard, So users can use the code with only one touch. There are rules and limitations for doing this as I tried to list most of them below:

  1. The message must contain the Code prase. Some other words like passcode and password are ok too in English.
  2. The Code phrase (with or without :) must be separate with only one space with your numbers.

example:

Code 1111111
Code: 111111
  1. The OTP number must be English NOT your localized.
  2. The Code phrase can be localized into your preferred language.

example:

English: Code
Spanish: Codingo
Germany: Kode
Czech: Kod
Persian: رمز
Arabic: رمز
  1. The code should have more than 4 digits

Code

In code, just set the textField content type to the one-time password.

otptextField.textContentType = .oneTimeCode

Note

The code appears only on top of the standard system keyboard requires user action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment