Access most recently used emojis list in iOS

2019-05-01 17:39发布

问题:

In iOS, in the native Emoji keyboard, you can see your most recently used Emojis. I would like to know if it is possible to get the data on those Emojis (which is app-independent) from inside my app.

My goal is to display the most used emoji, given a user, in my app.

回答1:

If you just want an Emoji selector you could use/modify libraries like SYEmojiPopover or AGEmojiKeyboard which allows you to have full control on the output without messing with the iOS internals (albeit the "recents" list will be app-specific).


On iOS 9 the preferences are stored in the com.apple.EmojiPreferences suite, which you could extract the list of most recently used emoji by:

// swift 3:
let prefs = UserDefaults(suiteName: "com.apple.EmojiPreferences")!
let defaults = prefs.dictionary(forKey: "EmojiDefaultsKey")!["EmojiRecentsDefaultsKey"]! as! [String: Any]
let recents = defaults["RecentsKey"]! as! [String]
print(recents)

// swift 2:
let prefs = NSUserDefaults(suiteName: "com.apple.EmojiPreferences")!
let recents = prefs.dictionaryForKey("EmojiDefaultsKey")!["EmojiRecentsDefaultsKey"]!["RecentsKey"]! as! [String]
print(recents)

// prints e.g. ["