Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MFMailComposeViewController not dismiss

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];
}
like image 412
user2474320 Avatar asked Mar 09 '26 02:03

user2474320


1 Answers

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];
}
like image 67
user2474320 Avatar answered Mar 10 '26 19:03

user2474320



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!