通过UIPasteBoard将图像粘贴到短信中

| 我想做的是从我的应用程序中将一些图像粘贴到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];
}
在调试模式下,我发现该图像确实存在,并且确实进入了粘贴板(我检查了该图像,并通过粘贴板中的图像引入了imageview,这是必需的)。 保存到剪贴板后,我打电话
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@\"sms:\"]];
它确实会弹出,但是当我点击“文本框”时,没有粘贴按钮显示。 有人可以指出我的错误吗? 还是这样做有意义?我的意思是,是否可以通过默认iPhone Message App发送图像?     
已邀请:
仅当粘贴板包含您点击的当前对象(此处为“文本字段”)支持的项目时,才会显示“粘贴”操作。似乎您仅在粘贴板上添加了图像。文字栏位不支援图片。因此,“粘贴”操作不会显示。     
我有这个工作。我只是使用setData为其提供原始数据,然后使用forPasteboardType设置数据类型。就在您的下方
    if (fileExists){
尝试这个
    NSData *data = [NSData dataWithContentsOfFile:imagefile];
    [pasteboard setData:data forPasteboardType:@\"public.png\"];            
您可以在此处查找其他PasteboardType UTI \。     
这段代码工作正常:
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@\"imageName\"]];
[[UIPasteboard generalPasteboard] setImage:image];
    

要回复问题请先登录注册