MFMailComposeViewController 未在横向模式下打开。但是在纵向模式下工作

MFMailComposeViewController not opening in Landscape mode. But working in portrait mode

在花了一些时间查看有关堆栈溢出的类似问题后,不幸的是 none 似乎解决了我的问题。

我正在使用 UIActionSheet,当用户点击发送电子邮件操作 sheet 时,将调用以下代码:

if ([MFMailComposeViewController   canSendMail]){
                NSString *emailTitle = @"bla bla bla";
                // Email Content
                NSString *messageBody = @"bla bla bla";
                // To address
                NSArray *toRecipents = [NSArray arrayWithObject:@"test@test.com"];

                MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
                mc.mailComposeDelegate = self;
                [mc setSubject:emailTitle];
                [mc setMessageBody:messageBody isHTML:NO];
                [mc setToRecipients:toRecipents];


                [self.view.window.rootViewController presentViewController:mc animated:YES completion:NULL];
                NSLog(@"email view opened");
            }
                else{
                    UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No mail account setup on device" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
                    [anAlert addButtonWithTitle:@"Cancel"];
                    [anAlert show];
                }

MFMailComposeViewController 在我的 iPhone 上以纵向模式打开,但在 iPad 上以横向模式打开应用程序时,没有任何反应。没有视图弹出,什么都没有。 它在 NSLog 中显示 "email view opened" 但没有其他内容。 想法?

编辑 该应用程序仅在 iPhone 上是纵向的,在 iPad

上是任何方向

再次编辑 玩了一会儿之后,如果我将代码分配给一个按钮,它工作正常,只有当从操作 sheet 中选择电子邮件时才会出现这个问题

找到答案了,就是这样:

dispatch_async(dispatch_get_main_queue(), ^ {
    // INSERT EMAIL CODE HERE
});