xcode 应用内截图并附加到电子邮件,无需保存到库中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6450303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
in-app Screenshot and attach to email without saving into library
提问by Clarence
I would like to know what code should i use if i want to make my app able to take a screenshot of the screen by pressing a UIbutton and immediately pop up and Mail compose and email out the screenshot without saving it into photo library?
我想知道如果我想让我的应用程序能够通过按下 UI 按钮来截取屏幕截图并立即弹出邮件撰写并通过电子邮件发送屏幕截图而不将其保存到照片库中,我应该使用什么代码?
Many thanks!
非常感谢!
回答by Deepak Danduprolu
You will need to add two frameworks to your project - QuartzCore
and MessageUI
and then do #import <QuartzCore/QuartzCore.h>
and #import <MessageUI/MessageUI.h>
.
您将需要两个框架添加到您的项目-QuartzCore
和MessageUI
,然后做#import <QuartzCore/QuartzCore.h>
和#import <MessageUI/MessageUI.h>
。
Your button press code should be like,
你的按钮按下代码应该是这样的,
- (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];
}
}