I am building my first custom keyboard. I am using Swift 2 and Xcode 7. I have this as my keyboard
(I am running it on my iPhone) When I tap the little alien face, I would like to have either
a little emoji with that image or
insert the image (if possible) to where the user is typing. I have 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 have been unsuccessful. When I print(data)
, I receive nil
, followed by an EXC_BAD_ACCESS
on the next line. How can I achieve either of the 2 goals I had? Thanks for your help.