IOS 5.0 Check if NSString contains Emoji characters

I have an iOS 5 application that allows users to enter a username using international keyboards. I want to check if the input (NSString *) contains an emoji character or not.

Disabling the emoji keyboard is not an option (using the UIKeyboardTypeASCIICapable as it disables some of the international keyboards).

I tried this one . But he does not detect some of these characters, like these .

Is there a good way to solve this problem?

+4
source share
4 answers

I managed to detect all emojis in iOS 5 and iOS 6 emoji keyboards using the following method https://gist.github.com/4146056

+10
source

Use the https://github.com/woxtu/NSString-RemoveEmoji Category, but note that in iOS 9.1 added more emojis that the above method does not recognize (especially these: 🤐🤑🤒🤓🤔🤕🤖🤗🤘🦀🦁🦂🦃 🦄🧀).

FIX: replace return (0x1d000 <= codepoint && codepoint <= 0x1f77f); in the isEmoji method using return (0x1d000 <= codepoint && codepoint <= 0x1f77f) || (0x1F900 <= codepoint && codepoint <=0x1f9ff); return (0x1d000 <= codepoint && codepoint <= 0x1f77f) || (0x1F900 <= codepoint && codepoint <=0x1f9ff);

+1
source

In iOS 10 and below, you should check if unicode is between the following values.

 if ((0x1d000 <= uc && uc <= 0x1f77f) || (0x1f900 <= 0x1f9ff)) { //is emoji } 
0
source
 NSData *data = [yourstringofemo dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; if ([goodValue rangeOfString:@"\u"].location == NSNotFound) { goodvalue string contains emoji characters } else { goodvalue string does not contain emoji characters } 
-1
source

Source: https://habr.com/ru/post/1434987/


All Articles