将屏幕截图添加到电子邮件而不保存到库

时间:2013-07-03 14:18:38

标签: ios screenshot

我需要能够在我的应用程序中发送一封电子邮件,其中附有iphone当前显示屏的屏幕截图。您单击一个按钮,我会将您带到附有屏幕截图的电子邮件中,而不会将图片保存到相机中。您按下的按钮应位于操作表中。我知道发送电子邮件和操作表的代码,但我需要知道如何使邮件的按钮位于操作表中,包括屏幕截图。

1 个答案:

答案 0 :(得分:1)

UIActionSheet *options = [[UIActionSheet alloc] initWithTitle:@"Options" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Email", nil];
[options showInView:self.view];

#pragma mark ActionSheet Delegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex)
    {
        case 0:
        {

        }
        default:
            break;
    }
}

#pragma mark Email

//Allocating Memory for MailComposer
    MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];    

    mailController.mailComposeDelegate = self;
   UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData *exportData = UIImageJPEGRepresentation(image ,1.0);
    [mailController addAttachmentData:exportData mimeType:@"image/jpeg" fileName:@"Screenshot.jpeg"];
    [self presentModalViewController:mailController animated:YES];

编辑:

#pragma mark MailComposer Delegate
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [self dismissModalViewControllerAnimated:YES];
}

请记住在头文件中添加MFMailComposeViewControllerDelegate。

希望这会对你有所帮助。