我的iOS6中的MFMailComposeViewController不再有效

时间:2012-10-23 22:01:26

标签: ios6 mfmailcomposeviewcontroller

注意到我用来模态弹出对话框发送电子邮件的MFMailComposeViewController不再适用于iOS6。它仍会弹出对话框,但我无法设置正文文本,也无法在视图中输入任何内容。我所能做的就是按取消。

该类实现MFMailComposeViewControllerDelegate接口,这里是一些代码:

//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];
}

它在iOS5中运行良好。

2 个答案:

答案 0 :(得分:1)

我通过将MyEmailSender更改为UIViewController而不是NSObject来解决此问题。出于某种原因,这解决了在iOS6中运行时的问题。新代码如下:

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


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

现在它适用于iOS5和iOS6。

答案 1 :(得分:0)

我修复了完全相同的问题(在iOS6中:空白作曲家屏幕,只有取消按钮有效。而在iOS5中,相同的代码工作正常。)

我做了导入:

#import <MessageUI/MFMailComposeViewController.h>

但我忘记了这一点:

#import <MessageUI/MessageUI.h>

添加了MessageUI.h的导入后,iOS 6上没有更多问题。