Sending images with iOS 8 custom keyboard?

馋奶兔 提交于 2019-12-09 11:15:24

问题


I've been developing a custom keyboard for iOS 8, but stumbled upon a problem trying to send images using the keyboard. I did some research and it seems like there isn't a simple way to do this with UITextDocumentProxy because only NSStrings are allowed.

Am I either overlooking any simple ways to use a custom keyboard to send images and/or is there any way to work around this issue?

Thanks in advance


回答1:


Apparently, you are not the only person to try a keyboard like this. If you look at the animated GIF on the site, the keyboard uses copy/paste to add the image to the messages.

The UIKeyInput Protocol, which is inherited by UITextDocumentProxy, has the following function:

func insertText(_ text: String)     //Swift
- (void)insertText:(NSString *)text //ObjC

These only take a String or an NSString, as you already know. Because there are no other methods to insert content, it can be assumed that, currently, there is no other way.

Right now, I would suggest that you adopt a similar usage. When the user taps on the image, add it to the UIPasteboard. Maybe present a little banner on top of the keyboard saying, "You can now paste" or something, but that would be up to you to decide.



来源:https://stackoverflow.com/questions/25478893/sending-images-with-ios-8-custom-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!