JSA986
JSA986

Reputation: 5936

Cant dissmis email when attaching screenshot xcode 4.3

when I email a screenshot from my app I cant dimiss the email client when its called. Even if I hit cancel nothing happens, could someone advise me on what im doing wrong please.

- (void)btn:(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] self];
    mailComposer.delegate = self;
    [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];



    [self presentModalViewController:mailComposer animated:YES];

}

[self dismissModalViewControllerAnimated:YES];

Upvotes: 0

Views: 303

Answers (1)

Ian L
Ian L

Reputation: 5601

You need to set the delegate as mailComposer.mailComposeDelegate = self;

Then call the dismiss method in the mail composer delegate method:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    // Do any processing before dismissing
    [self dismissModalViewControllerAnimated:YES];
}

Upvotes: 1

Related Questions