应用内截图并附加到电子邮件,无需保存到库中 [英] in-app Screenshot and attach to email without saving into library

查看:50
本文介绍了应用内截图并附加到电子邮件,无需保存到库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果我想让我的应用程序能够通过按下 UI 按钮来截取屏幕截图并立即弹出并通过邮件撰写和通过电子邮件发送屏幕截图而不将其保存到照片库中,我应该使用什么代码?

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?

非常感谢!

推荐答案

你需要在你的项目中添加两个框架 - QuartzCoreMessageUI 然后执行 #import #import .

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>.

你的按钮按下代码应该是这样的,

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];
    }
}

这篇关于应用内截图并附加到电子邮件,无需保存到库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆