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

前端 未结 1 702
故里飘歌
故里飘歌 2020-12-29 16:46

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 a

1条回答
  •  一生所求
    2020-12-29 17:10

    You will need to add two frameworks to your project - QuartzCore and MessageUI and then do #import and #import .

    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 讨论(0)
提交回复
热议问题