Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get UITextField's textContentType property to do anything?

Here's the documentation on UITextField's textContentType property:

Use this property to give the keyboard and the system information about the expected semantic meaning for the content that users enter. For example, you might specify UITextContentTypeEmailAddress for a text field that users fill in to receive an email confirmation. When you provide this information about the content you expect users to enter in a text-entry area, the system can in some cases automatically select an appropriate keyboard and improve keyboard corrections and proactive integration with other text-entry opportunities.

Because the expected semantic meaning for each text-entry area should be identified as specifically as possible, you can’t combine multiple values for one textContentType property. For possible values you can use, see Text Content Types; by default, the value of this property is nil.

This seems pretty straightforward, but I can't figure out how to make this actually do anything. I created a simple demo app, added a text field, and set self.textField.textContentType = UITextContentTypeEmailAddress. Then I ran it on an iPhone 7 with iOS 10.0.1.

At the very least I expected this to automatically select the email keyboard, without having to explicitly set it. It does not—I get the standard keyboard on my iPhone.

I also expected it to show my own email addresses for the QuickType suggestions. I've seen this happen elsewhere—if I'm in Safari and it detects that I'm editing an email field, it shows my home and work email addresses as suggestions. Again, it does not do that here, even though the documentation suggests that it should.

Even if I also set the keyboardType to UIKeyboardTypeEmailAddress, I still don't get the QuickType suggestions I was expecting.

There's a WWDC talk that discusses this new capability, but there's never any suggestion that you need to do anything other than set this single property.

Am I missing some step, or does this not actually do what I'm expecting?

like image 869
robotspacer Avatar asked Sep 22 '16 07:09

robotspacer


3 Answers

This is finally supported in third party apps in iOS 11. I have an app built using the iOS 10.3 SDK installed on iOS 11 beta 1. It includes fields with textContentType = UITextContentTypeEmailAddress and these correctly suggest the two email addresses on my contact card. I also have fields with textContentType = UITextContentTypePostalCode that correctly suggest my zip code.

In addition to the existing types, iOS 11 also adds UITextContentTypeUsername and UITextContentTypePassword, which can be used to support Password AutoFill for Apps.

like image 85
robotspacer Avatar answered Nov 05 '22 08:11

robotspacer


Just for info (because i could hardly find it in google and apple docs):

In new ios apple provided a new features (look at image). Here is the description and wwdc about them.

  • Smart Dashes
  • Smart Insert
  • Keyboard lock

enter image description here

like image 4
Nik Kov Avatar answered Nov 05 '22 06:11

Nik Kov


I've battled on and off trying to get "auto-complete" to work by specifying .textContentType on a UITextField. It seemed hit or miss and I gave up many times. I revisited the issue today and learned a couple tricks to get it working (better).

• Set .spellCheckingType and .autocorrectionType to .no. When these properties are anything else, autocomplete does not work. To make matters worse, the default value for these properties is .default, so not setting them at all results in no auto-complete.

keyboardType = .numberPad does not seem to support auto-complete at all. When I switched to .numbersAndPunctuation, auto-complete for phone number started working.

All that done, sometimes a text field will still fail to use auto-complete every time. If I tap into a different field, and then back to the problematic one, auto-complete works. No explanation for this, still some mystery meat I have not discovered. But the tips above got me a lot closer..."

like image 1
Swany Avatar answered Nov 05 '22 07:11

Swany