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

后端 未结 2 2012
庸人自扰
庸人自扰 2020-12-28 11:21

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

2条回答
  •  旧巷少年郎
    2020-12-28 11:26

    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"

提交回复
热议问题