因此,将我的部分屏幕复制到粘贴板的代码可以正常工作,因为它成功地将其复制到我的相册中。但是,我希望能够将部分屏幕截图粘贴到新的 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
}