Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Custom keyboard: I want to send images to the textDocumentProxy(Input controls)

I am implementing custom keyboard with only images and wanted to send images to textDocumentProxy/input controls like textview on click of image but not get over it. so far I am able to send text/string to input controls but not images.

Is it possible to send images to input controls?

Any suggestion or solution is highly appreciated.

like image 356
Ajay Gabani Avatar asked Apr 03 '15 04:04

Ajay Gabani


People also ask

Can you create your own keyboard on iPhone?

The xKeyboard is a keyboard extension in which you can add special symbols and words as you needs. There are lots of unicode characters and special symbols you can use. You could use the custom keyboard you build in word, PPT, Excel, notes and other text apps on iPhone or iPad.

How do I add a custom keyboard to my iPhone?

Go to Settings > General > Keyboard. Tap Keyboards, then do any of the following: Add a keyboard: Tap Add New Keyboard, then choose a keyboard from the list. Repeat to add more keyboards.


2 Answers

Following is the code for the copy image into pasteboard

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://warp.povusers.org/images/test.png"]];
UIPasteboard *pasteBoard=[UIPasteboard generalPasteboard];
[pasteBoard setData:data forPasteboardType:@"public.png"];

Now the think is that create extension of custom keyboard in that layout you can put your UIButton and that button action implement above for png image.

For Local Image following code is help full to you and it's working in my case.

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

More Uniform Type Identifiers you visit here and change Pasteboard Type.

May this help lot and solve your problem.

Edited

"Allow Full Access" From Settings -> Keyboard -> Keyboards -> select your app keyboard -> On switch of "Allow Full Access"

like image 62
Nimit Parekh Avatar answered Nov 01 '22 03:11

Nimit Parekh


Please try in a device, you can test with iMessage App in a device. Default input views like UITextView and UITextField do not support the images. They only support the strings.

The following code will copy the image into the pasteboard.

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

And give "Allow Full Access" for keyboard in settings. And add the RequestsOpenAccess to YES in the info.plist file.

like image 24
Ramakrishna Avatar answered Nov 01 '22 01:11

Ramakrishna