joseph.hainline
joseph.hainline

Reputation: 26658

My MFMailComposeViewController in iOS6 no longer works

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.

Upvotes: 4

Views: 1257

Answers (2)

hotdogsoup.nl
hotdogsoup.nl

Reputation: 2329

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.

Upvotes: 0

joseph.hainline
joseph.hainline

Reputation: 26658

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.

Upvotes: 1

Related Questions