3

I'm manually setting the copied content in the pasteboard

@IBAction func onOkPressed( button: UIButton ) {
    var testImage = getImageWithColor(UIColor.redColor(), size: CGSize(width: 100, height: 100));
    UIPasteboard.generalPasteboard().image = testImage
}

func getImageWithColor(color: UIColor, size: CGSize) -> UIImage {
    UIGraphicsBeginImageContextWithOptions(size, false, 0)
    color.setFill()
    UIRectFill(CGRectMake(0, 0, 100, 100))
    var image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image
}

But when I paste the image into a textbox in simulator it doest not paste the image. I've tried this with a local png image as well instead of manually creating the image. When I paste onto the textbook in my custom keyboard app, it pastes the text from my mac clipboard instead of the image. However, if I programmatically do UIPasteboard.generalPasteboard().string = "TeST", the expect string gets pasted. Anyone know what could be wrong? Thanks.

Schemetrical
  • 5,506
  • 2
  • 26
  • 43
dchhetri
  • 6,926
  • 4
  • 43
  • 56
  • Please execute this code into original device rather then simulator. – Nimit Parekh Apr 13 '15 at 04:13
  • I do not have a developers account yet, but can you explain why it wouldn't work in a simulator? – dchhetri Apr 13 '15 at 04:16
  • Same issue happen when I develop keyboard app that time I not able to copy image into simulator then instal app into real device and in `settings -> General -> Keyboard -> Keyboards -> Add New Keyboard` . Then After Selected Keyboard and `"Allow Full Access"` switch ON. And then copy image into `PasteBoard` It's working in my case. – Nimit Parekh Apr 13 '15 at 04:20
  • Using my friends dev account. I'm able to install the app and add my keyboard app via Add New Keyboard setting, but I'm not able to select it after adding to see the 'Allow Full Access', is there something more I have to do for that? – dchhetri Apr 13 '15 at 05:40
  • Check your code in a real device and use the iMessage, notes or mail apps. This will work. – Ramakrishna Oct 14 '16 at 07:14
  • Same issue happen when I develop keyboard app that time I not able to copy image into simulator then instal app into real device and in settings -> General -> Keyboard -> Keyboards -> Add New Keyboard . Then After Selected Keyboard and "Allow Full Access" switch ON. And then copy image into PasteBoard It's working in my case.... But i am doing same, if i select "Allow Full Access" my app get crashed. – TBI Nov 11 '16 at 09:48

1 Answers1

9

Following is the tutorial for give Allow Full Access enable button in to settings.

Step 1 : Created extension into existed project.Into XCode -> New -> Target -> Left section Application Extension -> Select Custom Keyboard

enter image description here

Step 2 : Give name of the extension new target name.

enter image description here

Step 3 : For give Allow Full Access into extension's info.plist file and change the value of RequestsOpenAccess.

enter image description here

May This help lot.

Happy Coding.

Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72