4

Noticed that my MFMailComposeViewController that I use to modally pop a dialog to send email no longer works in iOS6. It still pops the dialog, but I can't set the body text, or input anything into the view. All I can do is press cancel.

The class implements the MFMailComposeViewControllerDelegate interface and here's some of the code:

//h file
@interface ASEmailSender : NSObject


//m file
@implementation MyEmailSender () <MFMailComposeViewControllerDelegate>
@end

@implementation MyEmailSender
...

- (void)emailFile:(ASFile *)file inController:(UIViewController *)viewController {
    MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
    if ([MFMailComposeViewController canSendMail]) {
        mailController.mailComposeDelegate = self;
        [mailController setSubject:@"my subject"];
        [mailController setMessageBody:@"msg body here" isHTML:NO];

        [viewController showIsLoading:YES];
        self.viewController = viewController
        [viewController presentModalViewController:mailController animated:YES];
    }   
}

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

It works great in iOS5.

joseph.hainline
  • 24,829
  • 18
  • 53
  • 70

2 Answers2

1

I fixed this by changing MyEmailSender to be a UIViewController instead of an NSObject. For some reason this fixes the problem when running in iOS6. The new code looks like:

//h file
@interface ASEmailSender : UIViewController <MFMailComposeViewControllerDelegate>


//m file
@implementation MyEmailSender
...
(same functions as before)

Now it works in both iOS5 and iOS6.

joseph.hainline
  • 24,829
  • 18
  • 53
  • 70
  • I am trying to learn more about this requirement in iOS 6. Do you happen to remember where you learned of it? – SAHM Oct 27 '12 at 12:19
  • @JPK, I didn't read that anywhere, just implied it because that fixed my problem. I'm rewording my answer to be more clear. Thanks. – joseph.hainline Oct 28 '12 at 05:04
  • I have issue with this component and the delegate it was already an UIViewController and on ios6 doesn't take the setMassageBody parameters –  Nov 05 '12 at 09:50
  • @matheszabi could you elaborate? It crashes when you call setMessageBody:isHTML? – joseph.hainline Dec 18 '12 at 03:25
0

I fixed the exact same problem (in iOS6: blank composer screen, only the Cancel button works. whereas in iOS5 the same code works fine.)

I did import:

#import <MessageUI/MFMailComposeViewController.h>

But I forgot this:

#import <MessageUI/MessageUI.h>

After adding the import of MessageUI.h, no more problems on iOS 6.

hotdogsoup.nl
  • 1,078
  • 1
  • 9
  • 22