[Solved] add screenshot to email without being saved to library


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

EDIT:

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

Remember to add the MFMailComposeViewControllerDelegate in the header file.

Hope this helps you.

8

solved add screenshot to email without being saved to library