How to show verification code suggestion on keyboard from Message - ios

I watched this video What's New in Cocoa Touch at WWDC 2018 and seen:
How to show this information?

Review WWDC 2018 Session 204 - Automatic Strong Passwords and Security Code AutoFill.
You will need to use a UITextField for entry and the system keyboard (no custom controls) and set the textContentType on it to .oneTimeCode (new in iOS 12).
let securityCodeTextField = UITextField()
securityCodeTextField.textContentType = .oneTimeCode
The operating system will detect verification codes from Messages automatically (messages that contain the word "code" or "passcode") with this UITextContentType set.

For those who's searching how to do that in HTML: need to add autocomplete="one-time-code" for your input field.
<input id="single-factor-code-text-field" autocomplete="one-time-code"/>
(from Apple Docs)
However, that will not work in most Android phones. For Android it's more complicated: https://web.dev/sms-otp-form/. You will need to add #domain #code to SMS text and also implement extra JS to pickup the code.

Storyboard
Select UITextField > Show the Attributes inspector > Text Input Traits > Content Type > One Time Code

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
singleFactorCodeTextField.textContentType = .oneTimeCode
Important
tvOS apps can also support Password AutoFill using the same
content-type settings. The AutoFill QuickType bar appears above the
keyboard when entering passwords with an iOS device using the Control
Center keyboard, the Remote app, or the Continuity Keyboard. Focus is
also advanced to the login button when the login fields are populated.
Warning
If you use a custom input view for a security code input text field,
iOS cannot display the necessary AutoFill UI.

if you have a website and you want to use some OTP sms authentication
you should use code: or passcode: before your OTP message.

Related

How can I get the current SIM number in iPhone?

I know that unlike the operator name and the country code, it's not possible to get the user's phone number in iOS programmatically (at least not with publicly available APIs).
But I have just tried the app Lyft and it is autosuggesting my current phone number. I want to know how this app is doing that.
The phone number suggestion appearing above the keyboard is a built-in iOS feature and it works if a Text Content Type is set for a UITextField.
Since iOS 10, you can provide a content type for your inputs. iOS then will recommend autofill options for the given content type.
You can set up a content type...
in Interface Builder by navigating to the Text Input Traits section of the Attributes inspector (the fourth icon from the right in the top sidebar):
...or programmatically with:
textField.textContentType = .telephoneNumber

iOS Custom Keyboard Types

I'm worked on a custom keyboard and Apple review team rejected it because the keyboard does not support 'Numbers and Decimals' types.
So, I found that the problem is that when a text field requires those specific type of keyboard (for example to inset age, measures, or other numeric values), my keyboard 'misses to respond'.
I understood, reading from Apple documentation, that you must respond to the UIKeyboardTpye property per text object's.
I searched for specific delegate of the UIInputViewController but I wasn't able to find something close to that.
In this forum I found that one good place to examine the current keyboard type required is the textDidChange: delegate, but, it is not called.
I suppose this responder is called when your keyboard, somehow, 'declares' to iOS that it can handle Numbers or Decimal types. In fact I created a simple app with a simple UITextView that requires the Decimal keyboard type:
textView.keyboardType = UIKeyboardTypeDecimalPad;
And I put a NSLog() in the keyboard extension Input View Controller textDidChange: delegate.
As I tap on the text view my delegate is not called, instead the standard Decimal keypad is shown and in the Xcode console I see the following message:
Can't find keyplane that supports type 8 for keyboard iPhone-Portrait-DecimalPad; using 405786210_Portrait_iPhone-Simple-Pad_Default
I noticed also that this message comes when the UITextView requires the not-allowed keyboard types, i.e. the phonepad. All other keyboard types do not issue that message and the custom keyboard is shown and the textDidChange: delegate is correctly called.
The Numbers and Decimal types are surely allowed and are a MUST for the review team guys. Why the behave as a forbidden-types?
I think we need to 'declare', for example in the info.plist that our extension supports various keyboard types, but... well or more simply... I do not get the point... so... I'm asking... How can I add multiple keyboard types to my keyboard extension??
Thank you very much for help!
After the second rejection of my keyboard extension they sent me a screenshot. I noticed that they, generally, test apps on iPad. This made me think.
After some test it came out that the Numbers and Decimal types do not respond the same way on iPhone and iPad.
On iPhone a text view requiring Numbers or Decimal type keyboard always shows the iOS keypad, i.e. the custom extension is not called.
On the other side, on the iPad a text view requiring Numbers or Decimal type keyboard activates the custom extension.
Finally, after provided a standard numeric keypad (even if my keyboard uses hand-written techniquies) it was approved.

Shortcuts or autofill for contact info in UITextFields

When I'm in Safari in iOS, and I hit a form that requires I enter name and address, I get shortcuts in the keyboard area. For example, here is the keyboard when the focus is in a first name field. I can tap "Robert" instead of typing a name.
A similar thing happens for fields for last name, phone, email, zip code.
Can I get a similar thing in a native iOS app, in a UITextField? Is there a way to mark a field so that the keyboard will offer these shortcut suggestions?
You can turn on or off it by set autocorrectionType of UITextField. Default value of autocorrectionType is UITextAutocorrectionTypeDefault . It means you don't need to do anything, by default it will be showed.
UITextAutocorrectionTypeYes; // Turn on
UITextAutocorrectionTypeDefault; // Turn on
UITextAutocorrectionTypeNo; // Turn off
But beside of set autocorrectionType value, you need to make sure Predictive in Keyboards Setting of device is turned on. If Predictive is turned off, suggestion won't be displayed even you changed autocorrectionType to UITextAutocorrectionTypeYes.
UPDATE
You can change textContentType to choose with type of suggestion will be shown. Suggestions are from the Contacts. For example, you want phone suggestion
textField.textContentType = UITextContentTypeTelephoneNumber;
One note, if you have email and password on a screen, sometimes the native keychain detection overrides textContentType=email so autofill using textContentType stops working for the email field. For things like "create account" where they don't likely have existing credentials in keychain it's best to disable the keychain. To fix this
To disable keychain, just do this: passwordTextField.textContentType = #"";
Then email autofill should work again:
emailTextField.textContentType = UITextContentTypeEmail;
For iOS 13, I've found that email suggestions are only enabled if you set all 3 of the following properties:
emailTextField.textContentType = .emailAddress
emailTextField.keyboardType = .emailAddress
emailTextField.autocorrectionType = .yes
You can do it programatically or via storyboard.
My Observation in iOS 13.2 is, I disabled Auto-fill option from keychain settings.
And then it started suggesting the email
with
emailTextField.textContentType = .emailAddress

How can I change some keystroke on iOS 7 default keyboard? Like Slack

I use an app called "Slack" somehow they managed to change the return key to be "#" and "#" like in the picture.
I really don't know whether they created a whole new keyboard view that look exactly the same as iOS default keyboard or
It has a way to custom the return button of the default keyboard.
Anyone got any idea how can they do this on iOS 7?
Slack has shared it source code for handle message like app here
Which I still cannot locate where is the functionality to add "#" and "#"
You can achieve this by using the Twitter keyboard built in to the iOS SDK.
[textField setKeyboardType:UIKeyboardTypeTwitter];
If you're using Interface Builder, select your UITextField and go to the Attributes inspector -> Keyboard Type -> Twitter.

Would it be OK to add a custom button on a system keyboard in iPad

I have a requirement wherein I have to change the text of the return key of the iPad to Sign-in. Obviously it is not one of the options available in the sdk. I have searched it over the net and it seems doing that possible.
The only question remaining is whether the app would be accepted by Apple if I modify the default system keyboard? The HIG is not clear on this , it states that "A custom input view can replace the system-provided onscreen keyboard in apps" and "You can also provide a custom input accessory view, which is a separate view that appears above the keyboard (or your custom input view)". Nothing about whether we are allowed to add an extra button on a system keyboard.
Any experiences??
#Vin you can change the name of return key of the keyboard to your requirement. I have an app that has the changed to return key name to Done and Search. And apple did not reject it.
To "Sign-In" you can use the return key UIReturnKeyJoin
textField.returnKeyType = UIReturnKeyJoin;
EDIT
Nope. You get the return key and
keyboard types defined in the OS.
Unless you want to try to hack the
keyboard's view hierarchy to change
that button, which would be a really
bad plan. (Standard recommendation
here is to file a bug report with
Apple to let them know you'd like
more/different options.)
see Custom iPhone return key text
Since I didn't get any satisfactory answer, I convinced the client that it would be inappropriate to modify the default system keyboard for a sake of one button(even if it is allowed by Apple). We are now going for the "Go" option available for return key.

Resources