My app is a rich editor which uses UIWebView
and HTML5's contenteditable
feature.
Now, my app have some problem to deal with copying web content from safari to my UIWebView when the web content has any image.I want to replace the image html tag <img>
in the UIPasteboard
to some of my images.
However, when I using the following code to check the pasteboard, there is NO any image in pasteboard. But copy/paste image from safari to my app is working fine.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSLog(@"clip board strings = %@", pasteboard.strings);
NSLog(@"clip board urls = %@", pasteboard.URLs);
NSLog(@"clip board images = %@", pasteboard.images);
If I copy some image & text from safari then open my app, the NSLog is below:
2012-04-20 14:53:37.558 clip board strings = (
"text"
)
2012-04-20 14:53:37.559 [46800:17903] clip board urls = (
)
2012-04-20 14:53:37.559 [46800:17903] clip board images = (null)
I want to ask, how to get the image info from UIPasteboard and how to manipulate it?
Thanks in advance.
You can extract the image out of pasteboard using:
UIImage *image = [UIPasteboard generalPasteboard].image;
You can check whether pasteboard contains the image file using:
BOOL imgPasteBoard= [[pasteboard pasteboardTypes] containsObject:@"public.png"];
then by checking the bool value. You can also try using this code
[[UIPasteboard generalPasteboard] containsPasteboardTypes:UIPasteboardTypeListImage]; UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
if (pasteboard.image!= nil)
{
[self insertImage:pasteboard.image];
//insert image being a function where you write the code to insert Images to psteboard
}
hope this helps you..
Now load the UIImage using following code :-
NSData *imageData = UIImagePNGRepresentation(image);
[webView loadData:imageData MIMEType:imageMIMEType textEncodingName:nil baseURL:nil];
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