Is there a way to know if an Emoji is supported in iOS?

前端 未结 2 1321

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, t

相关标签:
2条回答
  • 2020-12-08 08:33

    Just for future reference, after discovering my app had 13.2 emojis not supported in 12.x versions, I used the answer from here: How can I determine if a specific emoji character can be rendered by an iOS device? which worked really well for me.

    0 讨论(0)
  • 2020-12-08 08:36

    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 extension

    private static let refUnicodeSize: CGFloat = 8
    private static let refUnicodePng =
        Character("\u{1fff}").png(ofSize: Character.refUnicodeSize)
    
    func unicodeAvailable() -> Bool {
        if let refUnicodePng = Character.refUnicodePng,
            let myPng = self.png(ofSize: Character.refUnicodeSize) {
            return refUnicodePng != myPng
        }
        return false
    }
    

    Discussion

    1. All characters will be rendered as a png at the same size (8) as defined once in

      static let refUnicodeSize: CGFloat = 8

    2. The undefined character U+1FFF image is calculated once in

      static let refUnicodePng = Character("\u{1fff}").png(ofSize: Character.refUnicodeSize)

    3. A helper method optionally creates a png from a Character

      func png(ofSize fontSize: CGFloat) -> Data?

    1. Example: Test against 3 emoji

    let codes:[Character] = ["\u{2764}","\u{1f600}","\u{1F544}"] // ❤️,                                                                     
    0 讨论(0)
提交回复
热议问题