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
For those who require international keyboards, this has worked well for iOS 9 and above:
Add the following extension function to check if a string contains emoji:
extension String {
var containsEmoji: Bool {
for scalar in unicodeScalars {
switch scalar.value {
case 0x3030, 0x00AE, 0x00A9,// Special Characters
0x1D000...0x1F77F, // Emoticons
0x2100...0x27BF, // Misc symbols and Dingbats
0xFE00...0xFE0F, // Variation Selectors
0x1F900...0x1F9FF: // Supplemental Symbols and Pictographs
return true
default:
continue
}
}
return false
}
}
Another extension function to remove the emoji's from the string:
extension String {
var minusEmojis: String {
let emojiRanges = [0x1F601...0x1F64F, 0x2702...0x27B0, 0x1D000...0x1F77F, 0x2100...0x27BF, 0xFE00...0xFE0F, 0x1F900...0x1F9FF]
let emojiSet = Set(emojiRanges.joined())
return String(self.filter { !emojiSet.contains($0.unicodeScalarCodePoint) })
}
}
Add a target to your text field like this:
textField.addTarget(self, action: #selector(didChangeText), for: .editingChanged)
Finally remove any emoji present from the target selector:
@objc func didChangeText(field: UITextField) {
if (field.text?.containsEmoji == true) {
field.text = field.text?.minusEmojis
}
}
Hope this helps someone! Cheers.