我的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中运行良好.

解决方法

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

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


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

现在它适用于iOS5和iOS6.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...