开发者

in-app Screenshot and attach to email without saving into library

开发者 https://www.devze.com 2023-03-15 01:03 出处:网络
I would like to know what code should i use if i want to make my app able to take a s开发者_StackOverflow社区creenshot of the screen by pressing a UIbutton and immediately pop up and Mail compose and

I would like to know what code should i use if i want to make my app able to take a s开发者_StackOverflow社区creenshot 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?

Many thanks!


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

精彩评论

暂无评论...
验证码 换一张
取 消