In Beta version of iOS 12 I have observed it gives OTP(from SMS) in keyboard suggestion.
So is there any API which they have created for developers ? Or that would just be an OS feature.

- 8,084
- 8
- 48
- 62

- 537
- 2
- 6
- 13
6 Answers
It is OS feature but you need to set UITextField
's input view’s textContentType
property oneTimeCode
.
otpTextField.textContentType = .oneTimeCode
NOTE: Security Code AutoFill will only works with System Keyboard it will not work with custom keyboard.
When you get OTP it will look something like this:

- 6,496
- 2
- 26
- 34
Unfortunately, you can't read the full message, you can only read the verify-code in the message.
Swift:
@available(iOS 12.0, *)
public static let oneTimeCode: UITextContentType
myTextField.textContentType = .oneTimeCode
Objective-C:
UITextContentType const UITextContentTypeOneTimeCode NS_AVAILABLE_IOS(12_0);
myTextField.textContentType = UITextContentTypeOneTimeCode;
These following verification code CAN be recognized by the system:
A pure number of lengths of 3-8
like : 123 1234 12345 666666 1234567 12345678 ...
These following verification code CANNOT be recognized by the system:
(i).length of code is less than 3 or more than 8 (ii).include letters
like : 1 12 123a 9h7d 123456789 ...
Others:
Security Code AutoFill will only works with System Keyboard. It will not work with custom keyboard.

- 358
- 4
- 12
-
What is the source of your info? Can we get a link. – Michael Ozeryansky Oct 30 '18 at 19:36
-
@MichaelOzeryansky Do you mean the test info ? No source. This is the result from my own test.. – 刘俊利 Oct 31 '18 at 01:53
-
The yellow text, the symbol ">", is used to quote something. I asked because it seemed you quoted some reference. – Michael Ozeryansky Nov 01 '18 at 04:33
-
I also saw that the limit of characters of the SMS is 70! – Matthew Usdin Nov 13 '19 at 10:41
-
@mattyU Where did you see it? – 刘俊利 Nov 14 '19 at 02:05
-
@刘俊利 it's the result of my test! – Matthew Usdin Nov 14 '19 at 09:51
-
See https://developer.apple.com/news/?id=z0i801mg and https://wicg.github.io/sms-one-time-codes/#format – Aure77 Jan 04 '22 at 13:30
There is no api, but you need set textContentType
as .oneTimeCode
of UITextField
property
otpTextField.textContentType = .oneTimeCode
one more thing,
If you use a custom input view for text field, iOS cannot display the necessary AutoFill UI.

- 7,204
- 4
- 49
- 61

- 2,338
- 1
- 18
- 30
Adding to other answers, after testing it seems that the text message needs to include either "Verification number" or "Code" before the number to work properly.
Working:
- Verification number 1234
- Verification number: 1234
- Verification code 1234
- Verification code: 1234
- Code 1234
- Code: 1234
- OTP 1234
- OTP: 1234
Not working:
- Number 1234
- Verification 1234
- 1234

- 31
- 1
- 3
Worthg mentioning that it seems "Autofill Passowrds" keyboard option needs to be turned on on the phone.

- 1,807
- 14
- 23
No there is no public API for that. It is automatically handled by OS. You just need to set UITextField's input view’s textContentType property to oneTimeCode.
textField.textContentType = .oneTimeCode

- 115
- 1
- 5