xcode – 应用内屏幕截图并附加到电子邮件而不保存到库中

前端之家收集整理的这篇文章主要介绍了xcode – 应用内屏幕截图并附加到电子邮件而不保存到库中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道我应该使用什么代码如果我想让我的应用程序能够通过按UI按钮截取屏幕截图并立即弹出并邮件撰写并通过电子邮件发送屏幕截图而不将其保存到照片库中?

非常感谢!

解决方法

您需要在项目中添加两个框架 – 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];
    }
}

猜你在找的Xcode相关文章