I am creating my first custom keyboard. I use Swift 2 and Xcode 7. I have it like my keyboard

(I run it on my iPhone) When I click on a small foreign face, I would like to have
a little emoji with this image or
paste the image (if possible) to where the user is typing. I tried this code
let pasteboard: UIPasteboard = UIPasteboard.generalPasteboard()
let image: UIImage = currentImage!
let newImage = scaleImage(image, toSize: CGSize(width: 40, height: 40))
let imgData: NSData = UIImagePNGRepresentation(newImage)!
pasteboard.setData(imgData, forPasteboardType: UIPasteboardTypeListImage[0] as! String)
let proxy = UITextDocumentProxy.self as! UITextDocumentProxy
let data = pasteboard.string!
print(data)
proxy.insertText(data)
but I did not succeed. When I print(data), I get nil, and then EXC_BAD_ACCESSon the next line. How can I achieve one of the two goals that I had? Thank you for your help.
source
share