Detect if a user has typed an emoji character in UITextView

前端 未结 9 1694
醉话见心
醉话见心 2020-12-05 08:13

I have a UITextView and I need to detect if a user enters an emoji character.

I would think that just checking the unicode value of the newest character would suffic

9条回答
  •  悲&欢浪女
    2020-12-05 08:50

    Another solution: https://github.com/woxtu/NSString-RemoveEmoji

    Then, after import this extension, you can use it like this:

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {
        // Detect if an Emoji is in the string "text"
        if(text.isIncludingEmoji) {
            // Show an UIAlertView, or whatever you want here
            return NO;
        }
    
        return YES;
    }
    

    Hope that helps ;)

提交回复
热议问题