5

When an Emoji character is set using the code below:

self.textField.text = @"\ue415";

It just display as a square. But when I input an Emoji from the keyboard it displays correctly. What's the problem?

PS: I'm using IOS 5.1

Text View with Emoji Characters

Perception
  • 79,279
  • 19
  • 185
  • 195
yakexi
  • 75
  • 1
  • 8
  • 2
    Check out my answer at : http://stackoverflow.com/questions/9886903/iphone-how-to-write-symbol-on-a-label/9887028#9887028 – Devang Mar 30 '12 at 09:28
  • 1
    I found the solution. In ios5.1 ,you must use Unicode 6.0,here is the mappings between Unicode 6.0 characters and Softbank PUA characters: http://opensource.apple.com/source/ICU/ICU-461.13/icuSources/data/translit/Any_SoftbankSMS.txt – yakexi Mar 30 '12 at 09:57
  • 3
    the solution: self.textField.text = @"\U0001F604"; – yakexi Mar 31 '12 at 14:01
  • Thanks yakexi! That link was exactly what I was looking for. – Giovanni Feb 24 '13 at 06:56

1 Answers1

2

In older versions of iOS the Emoji characters were all in the Unicode Private Use Area, which as the name suggests is a set of Unicode code points that explicitly don't have any associated characters. However, the Unicode standard has been updated to include a large number of Emoji characters, so iOS now uses these ones, as does Mac OS X.

You can see a list of all the Unicode Emoji in the code charts at www.unicode.org/charts e.g. http://www.unicode.org/charts/PDF/U1F600.pdf and these also tell you what each Emoji is actually meant to represent.

None of the Unicode Emoji are in the Basic Multilingual Plane of the Unicode spec, which means that they're all too big to fit in a single iOS unichar. So when they're stored in an NSString each emoji will cover multiple unichars — something to be aware of if you try to iterate over the characters in a string.

If you have code like

NSString *emoji =@"\U0001F604";
NSString *ascii = @"A";
NSLog(@"emoji.length %d, ascii.length %d", emoji.length, ascii.length);

You'll see this in the output

2013-03-08 14:42:22.841 test[23980:c07] emoji.length 2, ascii.length 1

where the single SMILING FACE WITH OPEN MOUTH AND SMILING EYES emoji is two unichars long, not one as we might expect.

Jonathan Caryl
  • 1,330
  • 3
  • 12
  • 30