How to clear font cache filled with emoji characters?

前端 未结 6 419
日久生厌
日久生厌 2020-12-13 19:52

I am developing keyboard extension for iPhone. There is an emoji screen smilar to Apples own emoji keyboard that shows some 800 emoji characters in UICollectionView

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 19:58

    Many emojis are represented by sequences that contain more than one unicode scalar. Matthew's answer works well with basic emojis but it returns only first scalar from the sequences of emojis like country flags.

    The code below will get full sequences and create a string that matches gemoji exported file names.

    Some simple smiley emojis also have the fe0f selector. But gemoji doesn't add this selector to file names on exporting, so it should be removed.

    func emojiToHex(_ emoji: String) -> String
    {
        var name = ""
    
        for item in emoji.unicodeScalars {
            name += String(item.value, radix: 16, uppercase: false)
    
            if item != emoji.unicodeScalars.last {
                name += "-"
            }
        }
    
        name = name.replacingOccurrences(of: "-fe0f", with: "")
        return name
    }
    

提交回复
热议问题