我想知道我应该使用哪些代码,如果我想让我的应用程序能够通过按UI按钮截取屏幕截图并立即弹出并邮件撰写并通过电子邮件发送屏幕截图而不将其保存到照片库中?
非常感谢!
答案 0 :(得分:12)
您需要在项目中添加两个框架 - QuartzCore
和MessageUI
,然后执行#import <QuartzCore/QuartzCore.h>
和#import <MessageUI/MessageUI.h>
。
你的按键代码应该是,
- (void)buttonPress:(id)sender
{
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(image, 1.0);
if ( [MFMailComposeViewController canSendMail] ) {
MFMailComposeViewController * mailComposer = [[[MFMailComposeViewController alloc] init] autorelease];
mailComposer.delegate = self;
[mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];
/* Configure other settings */
[self presentModalViewController:mailComposer animated:YES];
}
}