【问题标题】:My MFMailComposeViewController in iOS6 no longer works我在 iOS6 中的 MFMailComposeViewController 不再工作
【发布时间】:2012-10-23 22:01:26
【问题描述】:

注意到我用来模态弹出对话框以发送电子邮件的 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 中运行良好。

【问题讨论】:

    标签: ios6 mfmailcomposeviewcontroller


    【解决方案1】:

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

    //h file
    @interface ASEmailSender : UIViewController <MFMailComposeViewControllerDelegate>
    
    
    //m file
    @implementation MyEmailSender
    ...
    (same functions as before)
    

    现在它可以在 iOS5 和 iOS6 中使用。

    【讨论】:

    • 我正在尝试更多地了解 iOS 6 中的这个要求。你还记得你在哪里知道的吗?
    • @JPK,我没有在任何地方读到,只是暗示它,因为这解决了我的问题。我正在改写我的答案以更清楚。谢谢。
    • 我对这个组件有问题,委托它已经是一个 UIViewController 并且在 ios6 上没有使用 setMassageBody 参数
    • @matheszabi 你能详细说明一下吗?当你调用 setMessageBody:isHTML? 时它会崩溃
    【解决方案2】:

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

    我确实导入了:

    #import <MessageUI/MFMailComposeViewController.h>
    

    但我忘记了:

    #import <MessageUI/MessageUI.h>
    

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

    【讨论】:

    • 你的类是 NSObject 还是 UIViewController?
    猜你喜欢
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多