开发者

Pasting image in sms through UIPasteBoard

What I'm trying to do is to paste some images from my app in SMS.

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *imagefile = [[NSBundle mainBundle] 
                       pathForResource:@"imagename"]
                       ofType:@"png"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagefile];

if (fileExists){    
    UIImage *ui = [[UIImage alloc] initWithContentsOfFile:imagefile];
    pasteboard.image = ui;
    [ui release];
}

In debug mode I find out that the image DOES exist, and it DOES go to pasteboard (I checked it my introducing an imageview with the image from pasteboard, and it's the necessary one).

After saving to clipboard, I call

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:"]];

it does pop-up, but when i tap to "textfield开发者_如何学Python" there, no Paste button shows. Can somebody point at my mistake? Or does it make sense doing so? I mean, is it possible to send a image through Default iPhone Message App?


"Paste" action will be shown only if the paste board contains the supported item for the current object(here Text Field) you tapped. It seems that you are adding only an image to the paste board. Text Field doesn't support images. So "Paste" action doesn't show up.


I have this working. I just use the setData to give it raw data and then set the data type using forPasteboardType. Right below your

    if (fileExists){

Try this

    NSData *data = [NSData dataWithContentsOfFile:imagefile];
    [pasteboard setData:data forPasteboardType:@"public.png"];            

You can look up the different PasteboardType UTI's here.


This code is working fine:

UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"imageName"]];
[[UIPasteboard generalPasteboard] setImage:image];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜