Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine if a specific emoji character can be rendered by an iOS device?

With the release of iOS 9.1, we got a lot of cool new emoji like taco (🌮)! I'm working on an application where I'd like to show the new emoji characters on devices where they are supported but keep them hidden on devices where they are not. Is there a way to determine if a given emoji character (contained in an NSString) can be rendered on the device the app is running on?

After quite a bit of digging on SO and experimenting I've come up with a solution which I will post as an answer below, but please let me know if there's a better way.

like image 718
Joe Rideout Avatar asked Oct 27 '25 12:10

Joe Rideout


1 Answers

In response to the Swift question above, here's a Swift version based largely on an answer in this question: Get surrogate pairs from an emoji

func isEmojiSupported(emoji: String) -> Bool {
  let uniChars = Array(emoji.utf16)
  let font = CTFontCreateWithName("AppleColorEmoji", 0.0, nil)
  var glyphs: [CGGlyph] = [0, 0]
  return CTFontGetGlyphsForCharacters(font, uniChars, &glyphs, uniChars.count)
}
like image 136
mmorrison Avatar answered Oct 30 '25 01:10

mmorrison



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!