Question

I used MFMailComposeViewController for sending mail to others. When click a button the compose sheet is opening, and i can able to type To address,subject,message body. But after clicking send button the mail page is not closing.

code:

if ([MFMailComposeViewController canSendMail])
{
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    mailer.mailComposeDelegate = self;
    [mailer setSubject:@"My image"];


    UIImage *myImage = [UIImage imageNamed:@"mobiletuts-logo.png"];
    NSData *imageData = UIImagePNGRepresentation(myImage);           


    [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"Image"];
    NSString *emailBody = @"Hi, my image";
    [mailer setMessageBody:emailBody isHTML:NO];          

    [self presentViewController:mailer animated:YES completion:nil];
 } 

- (void)mailComposeController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    switch (result) {
        case MFMailComposeResultCancelled:
            break;
        case MFMailComposeResultSent:
            break;
        default:
            break;
    }

   [self dismissViewControllerAnimated:YES completion:nil];
}
Was it helpful?

Solution

Sorry. Forget to add these lines. After this lines mail working

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [self dismissViewControllerAnimated:YES completion:nil];
}

OTHER TIPS

Try this

[self presentModalViewController:mailer animated:YES];  

for dismiss

[self dismissModalViewControllerAnimated:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top