1

Apples build in Emoji Keyboard has a section with "Memoji" stickers. If you tap on any of these stickers (it seems to be a PNG image), then it's automatically inserted into the textfield or into the chat of the current App, for example WhatsApp, Facebook Messenger or iMessage.

WhatsApp with Memoji

Is it possible to get the same functionality with a custom keyboard? Or is Apple using some private API for the Memoji stickers?

I know how to add an image or image data to the pasteboard like UIPasteboard.general.image or UIPasteboard.general.setData(...). But if I do so, the png image isn't pasted automatically into the textfield. The user has to do additional steps and tap with the finger into the textfield and select "paste".

Robert
  • 161
  • 1
  • 3
  • 9

1 Answers1

0

All the mentioned apps use UITextView, upon selection of any sticker the OS adds this image as an NSTextAttachment to the attributedString of the text view

NSDavidObject
  • 328
  • 2
  • 5
  • 13
  • Thanks for your answer! So the “selection of any sticker” is some kind of private API? – Robert May 23 '21 at 06:47
  • Yeah, there's no direct access to selection from the keyboard. However, you're able to pull the image from the UITextView once inserted to reuse it however you wish. I actually mention how I accomplish this here: https://stackoverflow.com/a/67646151/2363439 – NSDavidObject May 23 '21 at 15:51