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
Related
How is Lyft suggesting my phone number in the QuickType bar so that I do not have to enter it manually? I know Apple introduced autofill functionality for usernames, passwords, security codes, and more with iOS 12 and it looks like this phone number suggestion may be using a similar function but I cannot figure out how to get any of my apps to suggest the phone number like Lyft is doing below.
From Interface Builder / Storyboard
Select a textField.
Show the Attributes inspector.
From Code
You can access this property in any UITextField
textField.textContentType = .telephoneNumber
As #Rob said in a comment below my question.
textField.textContentType = UITextContentType.telephoneNumber
Results in the behavior I was looking for. Thanks #Rob
Phone number autofill strong solution:
textField.keyboardType = .asciiCapableNumberPad
textField.textContentType = .telephoneNumber
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.
I am currently trying to display quick type suggestions for the user's email address when the user is editing the email text field as well as the email confirmation text field. To do that, I set two things:
the text field's textContentType as well as its autocorrectionType to get the quick type bar to appear.
However, it seems that setting the textContentType has no effect on the contents of the quick type bar; it simply displays "words" as they would appear when editing any other text field. This is obviously not the result I want my users to see.
Here is the current code:
SEL selector = NSSelectorFromString(#"textContentType");
// Make sure that the text field is actually able to process the event,
// the iOS version is greater than 10.3
if([self.emailTextField respondsToSelector: selector]){
self.emailTextField.textContentType = UITextContentTypeEmailAddress;
self.emailConfirmationTextField.textContentType = UITextContentTypeEmailAddress;
self.emailTextField.autocorrectionType = UITextAutocorrectionTypeDefault;
self.emailConfirmationTextField.autocorrectionType = UITextAutocorrectionTypeDefault;
}
From what I've read, this works for 3rd party apps only starting from ios 11
Open up Apple's Calendar app. When you name a new appointment, it automatically capitalizes the first letter. It does not use the 'correction' style swap-out to do this.
For the life of me I can not reproduce this behavior. In IB I have set the UITextField's Capitalization to Word, but it seems to have no effect at all. If I turn on correction, it will swap-out the word with a capitalized version, but this isn't quite right.
Do I need to handle this in code, by checking each key press? This is probably trivial, except I'm worried about all of the corner cases I will miss, such as when the user manually uses 'shift' to negate the capitalization, or deletes and re-keys, in which case it shouldn't capitalize.
Or maybe there's a way to simply load the textfield with shift pressed? Is this the common way of implementing it?
Setting the capitalization to Word should do this, so something else is going wrong. Are you certain that's toggled on the actual UITextField that you're testing? Are you sure you're not maybe overriding it in code somehow? You can set it programmatically with:
[myTextField setAutocapitalizationType:UITextAutocapitalizationTypeWords];
There's also an exception (per the docs) where this will be ignored:
Some keyboard types do not support auto-capitalization. Specifically,
this option is ignored if the value in the keyboardType property is
set to UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, or
UIKeyboardTypeNamePhonePad.
Does this apply to you?
Are you using the simulator or an actual device? If you are using the simulator, the casing will respect the shift and caps-lock state of the physical keyboard on your computer.
i just checked this in my app and it already did Capitalization by default. the behaviour is not determined by your application code, but by the global iphone settings.
start the iOS Settings. go to General, then Keyboard, there the user has the option for "Auto-Capitalization". is it off ?
in my case it was turned on, so my app and the calendar had this feature, when i turn it off, both apps are lacking this feature, because the user decided he does not want this feature.
Capitalization disable
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
To capitalize all characters
textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
To capitalize first character of sentence
textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
To capitalization of first character of all words in sentense
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
Certain keyboards ignore the capitalization type
Some keyboard types do not support auto-capitalization. Specifically, this option is ignored if the value in the keyboardType property is set to UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, or UIKeyboardTypeNamePhonePad.
More details on the developer reference
Here is a Swift 2.0 update for all characters:
SomeTextField.autocapitalizationType = UITextAutocapitalizationType.AllCharacters
I had the same issue with capitalization property, i just changed keyboard type to Default and everything start working as expected. In my case i had previously set keyboardType to NamePhonePad that don't support auto-capitalization.
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.