MFMailComposeViewController not dismissing

我与影子孤独终老i 提交于 2019-11-30 19:22:22

Use:

dismissViewControllerAnimated:completion:

DEPRECATED FROM IOS 6.0:

Add this method to your class:

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

Have fun

There could be several problems:

  1. Not adding protocol implemantation in the .h

    @interface yourClass : UIViewController <MFMailComposeViewControllerDelegate>
    
  2. Not adding the relevant function in .m:

    -(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:    (MFMailComposeResult)result error:(NSError*)error {
         [self dismissModalViewControllerAnimated:YES];
    }
    
  3. My error was not setting the correct delegate, but I fixed it :) and now it works for me:

     picker.mailComposeDelegate = self;
    

"dismissModalViewControllerAnimated:"is deprecated in iOS 6.0

iOS 7 use:

"dismissViewControllerAnimated:completion:"

Agat

I've described the problem and the way it can be solved more detailed here: https://stackoverflow.com/a/13576408/691660

I am not sure if Luda caught the core of the problem. No difference whether you specify the delegate or not, that does not work in case of modal+modal MFMailComposeViewController instance.

Swift Implementation:

Make sure your MFMailComposeViewController protocol and delegate is being called every time its function being executed.

This solves the issue of MFMailComposeViewController not being dismissed.

     let subj = "Test"
     let messageBody = "Test"
     let toRecipents = ["example@xyz.com"]
     let mc: MFMailComposeViewController = MFMailComposeViewController()
     mc.mailComposeDelegate = self
     mc.setSubject(subj)
     mc.setMessageBody(messageBody, isHTML: true)
     mc.setToRecipients(toRecipents)
     self.present(mc, animated: true, completion: nil)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!