如何禁用iOS 8表情符号键盘?

时间:2022-01-29 00:15:26

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 it how to get the string values from the emoji?

iOS 8中有什么选项可以停止显示表情符号键盘吗?它在numpad和安全文本中不可用,但在电子邮件中它是存在的。如果无法禁用它,如何从表情符中获取字符串值?

10 个解决方案

#1


88  

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.

使用界面构建器隐藏表情符号选择。

如何禁用iOS 8表情符号键盘?

#2


16  

This works on iOS 7 and 8:

这适用于iOS 7和8:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    // Disable emoji input
    return [textField textInputMode] != nil;
}

#3


8  

Just to update the great answers above for anyone facing the same issues as me:

为了更新以上这些伟大的答案,对于任何和我面临同样问题的人:

  1. An email field set as keyboardType = .EmailAddress still allows emojis
  2. 设置为keyboardType = .EmailAddress的电子邮件字段仍然允许使用emojis
  3. You may have more than one condition you want to filter
  4. 您可能有多个需要筛选的条件。
  5. Swift
  6. 斯威夫特
  7. Prevent C&P
  8. 防止c p

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.

NSASCIIStringEncoding的解决方案如果您希望为其他语言允许某些字符,那么它是不好的。

Some letters blocked with NSASCIIStringEncoding:

一些用NSASCIIStringEncoding屏蔽的字母:

  • All other versions of a: àáâäæãåā
  • 所有其他版本的:aaaaæaaā
  • All other versions of e: èéêëēėę
  • 所有其他版本的e:eeeeēėę
  • All other versions of o: ôöòóœøōõ
  • 所有其他版本的o:ooooœøōo

Using NSASCIIStringEncoding is not a good idea if you want to support users from other countries!

如果您想支持来自其他国家的用户,使用NSASCIIStringEncoding不是一个好主意!

I also tried NSISOLatin1StringEncoding:

我也试过NSISOLatin1StringEncoding:

  • Blocked versions of a: ā
  • 版本的阻塞:ā
  • Blocked versions of e: ēėę
  • 屏蔽版本的e:ēėę
  • Blocked versions of o: œø
  • 屏蔽版本的o:œø

This is much better clearly.

这显然要好得多。

I also tried NSISOLatin2StringEncoding:

我也试过NSISOLatin2StringEncoding:

  • Blocked versions of a: àæãåā
  • 版本的阻塞:aæaaā
  • Blocked versions of e: èêēė
  • 屏蔽版本的e:eeēė
  • Blocked versions of o: òœøōõ
  • 屏蔽版本的o:oœøōo

Worse.

更糟。

Edit2:

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
}

#4


7  

The solution that worked for me :

为我工作的解决方案:

self.texField.keyboardType = UIKeyboardTypeASCIICapable;

The emoji keyboard won't be available with that KeyboardType.

表情键盘无法用键盘输入。

But it's compulsory to check the kind of every char added in the textField, because the user can copy an emoji from elsewhere then paste it in.

但必须检查文本框中添加的每一个字符的类型,因为用户可以复制其他地方的表情符号,然后粘贴进来。

Here is how you could do so :

你可以这样做:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
     return [text canBeConvertedToEncoding:NSASCIIStringEncoding];
}

Be warned that, as I read in another post, this might also prevent user from using keyboard with special characters, like the Chinese one.

请注意,正如我在另一篇文章中看到的,这也可能会阻止用户使用带有特殊字符的键盘,比如中文键盘。

#5


5  

In swift 3.0

在斯威夫特3.0

textField.keyboardType = .asciiCapable

文本框。keyboardType = .asciiCapable

#6


2  

Swift 3.1 Solution

斯威夫特3.1解决方案

// MARK: - Text Field Delegate

 func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        return textField.textInputMode != nil
    }

#7


1  

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;
}

#8


1  

I wanted an answer for Swift 3.0 that would work on shouldChangeTextInRange and came up with the following that is really simple and can handle any language you throw at it (I include a photo using Chinese to demonstrate).

我想要一个适合于shouldChangeTextInRange的Swift 3.0的答案,我想到了下面这个非常简单的答案,它可以处理任何你想要的语言(我用中文展示了一张照片)。

The guard statement unwraps the optional text, and the return statement checks to see if it pulled out a value that satisfied the trimmingCharacters check. If there is a value (meaning it is not part of the current devices's input language), then it will not be empty, so the method returns false and does not allow the character to be entered.

保护语句打开可选文本,返回语句检查是否取出满足trimmingCharacters检查的值。如果有一个值(意味着它不是当前设备的输入语言的一部分),那么它就不是空的,因此方法返回false,不允许输入字符。

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    guard let text = (textField.text as NSString?)?.replacingCharacters(in: range, with: string) else {
        return true
    }

    return text.trimmingCharacters(in: CharacterSet.alphanumerics).isEmpty
}

This relies on Apple's CharacterSet.alphanumerics, so there is no need to maintain and update a list of approved characters, unless you want to add or remove items.

这取决于苹果的字符集。因此,不需要维护和更新已批准的字符列表,除非您想添加或删除项。

如何禁用iOS 8表情符号键盘?

Yay for language agnostic!

语言无关的,太棒了!

Another common use is for email, since the default email keyboard provides emojis. I found with a small modification, I was able to restrict characters to what I wanted for an email address to work.

另一个常见的用法是电子邮件,因为默认的电子邮件键盘提供了表情符号。我发现,只要稍加修改,我就可以将字符限制在我想要的电子邮件地址上。

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    guard let text = (textField.text as NSString?)?.replacingCharacters(in: range, with: string) else {
        return true
    }

    return text.trimmingCharacters(in: CharacterSet.alphanumerics).isEmpty ||
    !text.characters.filter { $0 == "@" || $0 == "." }.isEmpty
}

#9


1  

Though The Question is super old, I was Facing the same problem and was able to resolve it by the time this page loaded by this small trick :

虽然这个问题已经过时了,但我仍然面临着同样的问题,并且在这个页面被这个小技巧加载时,我已经解决了这个问题:

Simply Select "ASCII Capable" or "Numbers and Punctuations" in Interface Builder Xcode 8.2.1

只需在接口构建器Xcode 8.2.1中选择“ASCII支持”或“数字和标点”

如何禁用iOS 8表情符号键盘? 如何禁用iOS 8表情符号键盘?

Output is No Emoji Keyboard =D

输出不是表情符号键盘=D

如何禁用iOS 8表情符号键盘?

I'm sure it'll help Someone =)

我相信它会对某人有所帮助。

#10


0  

In Swift : - It Will restrict the to past the emoji in your TextView and Just change the keyboard type to ascii capable

在Swift: -它将限制到你的TextView中的emoji符号,并将键盘类型改为ascii

func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    var result = Bool()

            let disallowedCharacterSet1 = NSCharacterSet.symbolCharacterSet()
            let replacementStringIsLegal = text.rangeOfCharacterFromSet(disallowedCharacterSet1) == nil
            result = replacementStringIsLegal


        let newLength = textView.text!.utf16.count + text.utf16.count - range.length
        return newLength <= 300 && result // Bool

}

#1


88  

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.

使用界面构建器隐藏表情符号选择。

如何禁用iOS 8表情符号键盘?

#2


16  

This works on iOS 7 and 8:

这适用于iOS 7和8:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    // Disable emoji input
    return [textField textInputMode] != nil;
}

#3


8  

Just to update the great answers above for anyone facing the same issues as me:

为了更新以上这些伟大的答案,对于任何和我面临同样问题的人:

  1. An email field set as keyboardType = .EmailAddress still allows emojis
  2. 设置为keyboardType = .EmailAddress的电子邮件字段仍然允许使用emojis
  3. You may have more than one condition you want to filter
  4. 您可能有多个需要筛选的条件。
  5. Swift
  6. 斯威夫特
  7. Prevent C&P
  8. 防止c p

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.

NSASCIIStringEncoding的解决方案如果您希望为其他语言允许某些字符,那么它是不好的。

Some letters blocked with NSASCIIStringEncoding:

一些用NSASCIIStringEncoding屏蔽的字母:

  • All other versions of a: àáâäæãåā
  • 所有其他版本的:aaaaæaaā
  • All other versions of e: èéêëēėę
  • 所有其他版本的e:eeeeēėę
  • All other versions of o: ôöòóœøōõ
  • 所有其他版本的o:ooooœøōo

Using NSASCIIStringEncoding is not a good idea if you want to support users from other countries!

如果您想支持来自其他国家的用户,使用NSASCIIStringEncoding不是一个好主意!

I also tried NSISOLatin1StringEncoding:

我也试过NSISOLatin1StringEncoding:

  • Blocked versions of a: ā
  • 版本的阻塞:ā
  • Blocked versions of e: ēėę
  • 屏蔽版本的e:ēėę
  • Blocked versions of o: œø
  • 屏蔽版本的o:œø

This is much better clearly.

这显然要好得多。

I also tried NSISOLatin2StringEncoding:

我也试过NSISOLatin2StringEncoding:

  • Blocked versions of a: àæãåā
  • 版本的阻塞:aæaaā
  • Blocked versions of e: èêēė
  • 屏蔽版本的e:eeēė
  • Blocked versions of o: òœøōõ
  • 屏蔽版本的o:oœøōo

Worse.

更糟。

Edit2:

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
}

#4


7  

The solution that worked for me :

为我工作的解决方案:

self.texField.keyboardType = UIKeyboardTypeASCIICapable;

The emoji keyboard won't be available with that KeyboardType.

表情键盘无法用键盘输入。

But it's compulsory to check the kind of every char added in the textField, because the user can copy an emoji from elsewhere then paste it in.

但必须检查文本框中添加的每一个字符的类型,因为用户可以复制其他地方的表情符号,然后粘贴进来。

Here is how you could do so :

你可以这样做:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
     return [text canBeConvertedToEncoding:NSASCIIStringEncoding];
}

Be warned that, as I read in another post, this might also prevent user from using keyboard with special characters, like the Chinese one.

请注意,正如我在另一篇文章中看到的,这也可能会阻止用户使用带有特殊字符的键盘,比如中文键盘。

#5


5  

In swift 3.0

在斯威夫特3.0

textField.keyboardType = .asciiCapable

文本框。keyboardType = .asciiCapable

#6


2  

Swift 3.1 Solution

斯威夫特3.1解决方案

// MARK: - Text Field Delegate

 func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        return textField.textInputMode != nil
    }

#7


1  

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;
}

#8


1  

I wanted an answer for Swift 3.0 that would work on shouldChangeTextInRange and came up with the following that is really simple and can handle any language you throw at it (I include a photo using Chinese to demonstrate).

我想要一个适合于shouldChangeTextInRange的Swift 3.0的答案,我想到了下面这个非常简单的答案,它可以处理任何你想要的语言(我用中文展示了一张照片)。

The guard statement unwraps the optional text, and the return statement checks to see if it pulled out a value that satisfied the trimmingCharacters check. If there is a value (meaning it is not part of the current devices's input language), then it will not be empty, so the method returns false and does not allow the character to be entered.

保护语句打开可选文本,返回语句检查是否取出满足trimmingCharacters检查的值。如果有一个值(意味着它不是当前设备的输入语言的一部分),那么它就不是空的,因此方法返回false,不允许输入字符。

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    guard let text = (textField.text as NSString?)?.replacingCharacters(in: range, with: string) else {
        return true
    }

    return text.trimmingCharacters(in: CharacterSet.alphanumerics).isEmpty
}

This relies on Apple's CharacterSet.alphanumerics, so there is no need to maintain and update a list of approved characters, unless you want to add or remove items.

这取决于苹果的字符集。因此,不需要维护和更新已批准的字符列表,除非您想添加或删除项。

如何禁用iOS 8表情符号键盘?

Yay for language agnostic!

语言无关的,太棒了!

Another common use is for email, since the default email keyboard provides emojis. I found with a small modification, I was able to restrict characters to what I wanted for an email address to work.

另一个常见的用法是电子邮件,因为默认的电子邮件键盘提供了表情符号。我发现,只要稍加修改,我就可以将字符限制在我想要的电子邮件地址上。

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    guard let text = (textField.text as NSString?)?.replacingCharacters(in: range, with: string) else {
        return true
    }

    return text.trimmingCharacters(in: CharacterSet.alphanumerics).isEmpty ||
    !text.characters.filter { $0 == "@" || $0 == "." }.isEmpty
}

#9


1  

Though The Question is super old, I was Facing the same problem and was able to resolve it by the time this page loaded by this small trick :

虽然这个问题已经过时了,但我仍然面临着同样的问题,并且在这个页面被这个小技巧加载时,我已经解决了这个问题:

Simply Select "ASCII Capable" or "Numbers and Punctuations" in Interface Builder Xcode 8.2.1

只需在接口构建器Xcode 8.2.1中选择“ASCII支持”或“数字和标点”

如何禁用iOS 8表情符号键盘? 如何禁用iOS 8表情符号键盘?

Output is No Emoji Keyboard =D

输出不是表情符号键盘=D

如何禁用iOS 8表情符号键盘?

I'm sure it'll help Someone =)

我相信它会对某人有所帮助。

#10


0  

In Swift : - It Will restrict the to past the emoji in your TextView and Just change the keyboard type to ascii capable

在Swift: -它将限制到你的TextView中的emoji符号,并将键盘类型改为ascii

func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    var result = Bool()

            let disallowedCharacterSet1 = NSCharacterSet.symbolCharacterSet()
            let replacementStringIsLegal = text.rangeOfCharacterFromSet(disallowedCharacterSet1) == nil
            result = replacementStringIsLegal


        let newLength = textView.text!.utf16.count + text.utf16.count - range.length
        return newLength <= 300 && result // Bool

}