Is it possible to copy text/image to UIPasteboard in a keyboard extension? Similar to what popkey.co does with animated images.
I tested the following code and it doesn't seem to be working.
func copyImage() {
UIPasteboard.generalPasteboard().string = "copy test"
}
It always shows this error message:
UIPasteboard - failed to launch pasteboardd. Make sure it's installed in UIKit.framework/Support
Do you know about any other way to use copy&paste from a keyboard extension?
I was able to do it if I gave my custom keyboard "Full Access" in the Settings->General->Keyboard app. You need to include "RequestsOpenAccess" = YES in your Info.plist file. AND you have to toggle "Full Access" on in the Settings app.
Seems like Apple is restricting access to the general UIPasteboard otherwise.
First of all you have to get full access to your custom keyboard for use images / gifs ... on the iPhone Settings -> General -> Keyboards -> Keyboards -> Add New Keyboard... (Select your keyboard under THIRD-PARTY KEYBOARDS) -> click on your keyboard and toggle Allow Full Access
To do that you have to go to the to set RequestsOpenAccess = YES in the info.plist located in the keyboard extension folder.
Info.plist -> NSExtension -> NSExtensionAttributes -> RequestsOpenAccess -> YES
The following method will get the button tag check the tag in the switch statement and set the correct image according to the button tag to the pasteboard.
func btnPressed(sender: AnyObject) {
var btn = sender as UIButton
switch (btn.tag){
case 5:
let imageURL = NSBundle.mainBundle().pathForResource("cat", ofType: "png")
let data = NSData(contentsOfURL: NSURL(fileURLWithPath: imageURL!)!);
UIPasteboard.generalPasteboard().setData(data!, forPasteboardType: "public.png")
case 10:
let imageURL = NSBundle.mainBundle().pathForResource("dog", ofType: "png")
let data = NSData(contentsOfURL: NSURL(fileURLWithPath: imageURL!)!);
UIPasteboard.generalPasteboard().setData(data!, forPasteboardType: "public.png")
}}
User then can paste the image to any supported application...
Hope this helps !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With