5

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

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

I tried this. But it does not detect some of the characters like these.

Is there a good way to solve this problem?

CÇ.
  • 243
  • 5
  • 13

4 Answers4

10

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

CÇ.
  • 243
  • 5
  • 13
  • This is not correct. This solution will not work with unicode characters that Apple interprets as emojis but were actually around before the emoji characters were created and indexed in unicode. For example the 5th emoji character on the emoji keyboard (which has been around forever in unicode, before Apple changed it to an emoji) --> ☺ <-- that one is rendered as an emoji on an iPhone – Albert Renshaw Mar 19 '14 at 20:48
1

Use https://github.com/woxtu/NSString-RemoveEmoji Category, but note that iOS 9.1 added more emojis that above mentioned method doesnt recognize (especially these ones:).

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

Vahan
  • 2,176
  • 19
  • 17
  • This still allows for certain characters such as ☺️, add the following: (0x2100 <= codepoint && codepoint <= 0x26ff) – Leon May 31 '16 at 12:09
0

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

if ((0x1d000 <= uc && uc <= 0x1f77f) || (0x1f900 <= 0x1f9ff)) {
     //is emoji
}
Jorge Costa
  • 249
  • 2
  • 6
-1
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
}
NiravPatel
  • 3,260
  • 2
  • 21
  • 31