【发布时间】:2012-09-20 02:07:55
【问题描述】:
因此,将我的部分屏幕复制到粘贴板的代码有效,因为它成功地将其复制到我的相册。但是,我希望能够将部分屏幕截图粘贴到新的 SMS 消息中。我知道它必须手动完成(长时间按住消息和粘贴),但它要么什么都不粘贴,要么没有粘贴选项(因为它将它保存为字符串)。代码的中间部分是我正在努力的部分。任何帮助都会很棒。我已将 forPasteboardType 更改为“图像”,但这也不起作用。
//Capture part of Screen Shot
UIGraphicsBeginImageContext(self.view.bounds.size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c, 0, 98); //
[self.view.layer renderInContext:c];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Send Screenshot to Pasteboard
UIPasteboard *pasteBoard = [UIPasteboard pasteboardWithName:UIPasteboardNameGeneral create:YES];
pasteBoard.persistent = YES;
NSData *data = UIImagePNGRepresentation(viewImage);
[pasteBoard setData:data forPasteboardType:(NSString *)kUTTypePNG];
/////// Open SMS
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"Hello from me, paste image here -->";
controller.recipients = [NSArray arrayWithObjects:@"123456789", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
////// End SMS
}
【问题讨论】:
-
所以,我删除了中间部分,声明为“UIPasteboard *pasteBoard;”在我的 .h 文件中,添加了“pasteBoard = [UIPasteboard generalPasteboard];”在我的 ViewDidLoad 中,最后放上“pasteBoard.image = viewImage;”将图像发送到粘贴板。如果我手动打开一条新短信,我可以粘贴图片。我还在新电子邮件中工作。但是,当我尝试将其粘贴到我的应用程序中新创建的 SMS 中时,它不起作用?我想可能是因为我在正文中有文本,所以我删除了“controller.body”行,但仍然不能。我觉得我很接近了!
-
好的,我用这段代码打开了本地短信应用程序,NSString *stringURL = @"sms:"; NSURL *url = [NSURL URLWithString:stringURL]; [[UIApplication sharedApplication] openURL:url];
-
我现在可以将图像粘贴到本机 SMS 应用程序中。它仍然在我裁剪它的顶部显示一个白色边框。有什么想法吗?
标签: xcode uipasteboard