I'm building an iOS App, and Emojis play a big part in it.
In iOS 10.2, new emojis were released.
I'm pretty sure that if someone has iOS 8, for example, they wouldn't actually be able to see these emojis. Is there a way to detect this? I'm trying to dynamically build a list of all the Emojis that are supported on the user's iOS version, but I'm having a bit of trouble.
Clarification: an Emoji is merely a character in the Unicode Character space, so the present solution works for all characters, not just Emoji.
Synopsis
To know if a Unicode character (including an Emoji) is available on a given device or OS, run the
unicodeAvailable()
method below.It works by comparing a given character image against a known undefined Unicode character
U+1FFF
.unicodeAvailable(), a
Character
extensionDiscussion
All characters will be rendered as a png at the same size (8) as defined once in
static let refUnicodeSize: CGFloat = 8
The undefined character
U+1FFF
image is calculated once instatic let refUnicodePng = Character("\u{1fff}").png(ofSize: Character.refUnicodeSize)
A helper method optionally creates a png from a
Character
func png(ofSize fontSize: CGFloat) -> Data?
1. Example: Test against 3 emoji
2. Example: Test a range of Unicode characters
Helper function:
Character
to png► Find this solution on GitHub and a detailed article on Swift Recipes.