我的iOS6中的MFMailComposeViewController不再有效

前端之家收集整理的这篇文章主要介绍了我的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相关文章