Block Emoji-Keyboard for Text Input
I recently stepped over an issue during iOS app development for one of my customers. If the user switches to the Emoji-Keyboard on her iPhone during text input in a UITextField
or UITextView
and uses some of the icons the backend system for that app could not handle this. Implementing Emoji-Support on the server side would be a high effort.
The far more easier solution is to block the Emoji-Keyboard on the iOS side to prevent the user from using these characters. The UITextInputTraits
protocol defines the property keyboardType
of type UIKeyboardType
. By setting this property you can define the keyboard layout shown to the user, he starts typing into a UITextView
or UITextField
.
The enumeration UIKeyboardType
lists several keyboard layouts for email input, phone number input, or URL input for example. The property keyboardType
has the value UIKeyboardTypeDefault
as its default value. With this set the user may use Emojis from the Emoji-Keyboard if he has activated this in the settings on his iPhone. Deactivating the Emoji-Keyboard but still enabling the user to switch between different keyboard languages is rather simple: Just set the property keyboardType
to UIKeyboardTypeASCIICapable
. This sounds a little bit confusing as you might think, from now on only characters from the ASCII character set may be shown, but this is not true. The user has the full character set at hand, can switch to other language-related keyboards but the Emoji-Keyboard.
Every time you handle text input you should think about using the appropriate keyboard layout and switching to UIKeyboardTypeASCIICapable
.