Is there any option to stop showing the emoji keyboard in iOS 8? It is not available in numpad and secure text but for email it is there. If it is not possible to disable i
Try this:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([textField isFirstResponder])
{
if ([[[textField textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textField textInputMode] primaryLanguage])
{
return NO;
}
}
return YES;
}
for more info see here.
EDIT :
You can hide emoji from Keyboard using this code:
txtField.keyboardType=UIKeyboardTypeASCIICapable;
EDIT :
Hide emoji selection from keyboard using Interface builder.
Just to update the great answers above for anyone facing the same issues as me:
This is how we did it:
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
if !string.canBeConvertedToEncoding(NSASCIIStringEncoding){
return false
}
//other conditons
}
Edit
Okay the solution with NSASCIIStringEncoding is no good if you want to allow certain characters for other languages.
Some letters blocked with NSASCIIStringEncoding:
Using NSASCIIStringEncoding is not a good idea if you want to support users from other countries!
I also tried NSISOLatin1StringEncoding:
This is much better clearly.
I also tried NSISOLatin2StringEncoding:
Worse.
Edit2:
The following seems to work:
extension String {
func containsEmoji() -> Bool {
for i in self.characters {
if i.isEmoji() {
return true
}
}
return false
}
}
extension Character {
func isEmoji() -> Bool {
return Character(UnicodeScalar(0x1d000)) <= self && self <= Character(UnicodeScalar(0x1f77f))
|| Character(UnicodeScalar(0x1f900)) <= self && self <= Character(UnicodeScalar(0x1f9ff))
|| Character(UnicodeScalar(0x2100)) <= self && self <= Character(UnicodeScalar(0x26ff))
}
}
Now we call:
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
if string.containsEmoji() {
return false
}
//other conditons
}
In swift 3.0
textField.keyboardType = .asciiCapable
This is swift version.
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
if textView.isFirstResponder() {
if textView.textInputMode?.primaryLanguage == nil || textView.textInputMode?.primaryLanguage == "emoji" {
return false;
}
}
return true;
}
This works on iOS 7 and 8:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
// Disable emoji input
return [textField textInputMode] != nil;
}
Swift 3.1 Solution
// MARK: - Text Field Delegate
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
return textField.textInputMode != nil
}