2014-09-22 47 views
9

当我运行Xcode 6并使用iOS 8模拟器时,我试图加载一个MFMailComposeViewController,它没有出现。相反,我得到这个错误...MFMailComposeViewController不显示在iOS 8中

“警告:试图提出MFMailComposeViewController:0x7c30c400上的ViewController:0x7baf6000这已经是呈现(空)”

这完全相同的代码已经工作了将近一年了,不变。 可以肯定的是,我使用iOS 7.1模拟器在Xcode 6中运行我的应用程序,它的工作方式与以前完全一样。

有谁知道如何在iOS 8中显示MFMailComposeViewController视图? 这看起来像一个简单的任务,我相信它是一个简单的修复。

PS。不需要发帖,因为它是标准的代码,但在这里它是无论如何...

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 

picker.mailComposeDelegate = self; 

//Current Date 
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
NSDate *date = [NSDate date]; 
//Ensure UTC DATE 
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 
[formatter setDateFormat:@"MM/dd/yyyy 'at' HH:mm:ss UTC"]; 
NSString *myString = [formatter stringFromDate:date]; 

NSString *emailBody = [NSString stringWithFormat:@"Feedback time at %@.<br><br>Name:", myString]; 
[picker setMessageBody:emailBody isHTML:YES]; 

NSString *subject, *emailAddress; 

[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 
[formatter setDateFormat:@"MM/dd/yyyy"]; 
subject = [NSString stringWithFormat:@"Feedback"]; 

//Set the Subject 
[picker setSubject:subject]; 

emailAddress = @"[email protected]"; 

//Set the Receivers 
NSArray *myReceivers = [[NSArray alloc] initWithObjects:emailAddress, nil]; 
[picker setToRecipients:myReceivers]; 

//It saves the file name as the same as Subject here! 
picker.navigationBar.barStyle = UIBarStyleDefault;//UIBarStyleBlack; 
[self presentViewController:picker animated:YES completion:^{}]; 

回答

5

我有一个类似的问题,但没有得到同样的消息。但是在iOS 8上我的邮件编辑器不会显示。我从UIPopover上的一个按钮启动它。我会显示邮件撰写和代码,然后几行后,我叫:

[myPopover dismissPopoverAnimated:YES]; 

在计算器上另一个线程表示,也许有一些东西需要与其他视图控制器活跃。所以,我提出我的解雇酥料饼的其他呼叫上面显示邮件撰写,也使得它没有设置动画:

[aboutPopover dismissPopoverAnimated:NO]; 

现在,它的工作原理。

+0

就是这样。我还从UIPopover上展示了它,并且在打开MailComposer之前添加了该行以解除它,并且它工作正常!谢谢 – Airtower 2014-09-23 02:02:33

-1

这里是我用来显示邮件撰写的代码,它工作得很好我的版本的Xcode 6.0.1和我的设备(iPhone 5 iOS8上):

-(void) showMailComposer { 
    if(![MFMailComposeViewController canSendMail]) { 
     NSLog(@"Cannot send mail\n%s", __PRETTY_FUNCTION__) ; 
     return ; 
    } 

    // Email Subject 
    NSString *emailTitle = @"Test Email"; 
    // Email Content 
    NSString *messageBody = @"iOS programming is so fun!"; 
    // To address 
    NSArray *toRecipents = [NSArray arrayWithObject:@"[email protected]"]; 

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

    // Present mail view controller on screen 
    [self presentViewController:mc animated:YES completion:NULL]; 
} 
+0

我试图复制并粘贴该确切的代码,并使用它,但我得到确切同样的错误。 – Airtower 2014-09-22 17:27:48

+0

这可能是一个长镜头,但是你有最新版本的Xcode吗? – ElectrikSheep 2014-09-22 17:52:29

0

MFMailComposeViewController不再适用于iOS的8模拟器。

如果你尝试了物理设备上,你能尝试只呈现选择器,没有任何其他的变化,像这样:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
[self presentViewController:picker animated:YES completion:nil]; 

它大概也值得一试什么[MFMailComposeViewController canSendMail]返回

+0

我没有在设备上尝试过它。 – Airtower 2014-09-22 16:19:24

+0

我只是在不同的iPad上试了一遍,没有运气 – Airtower 2014-09-22 17:25:38

+0

@Airtower'[MFMailComposeViewController canSendMail]'返回什么?你有没有试过运行上面的两行代码?你在控制台输出中收到任何消息吗?你有任何崩溃?你在导入MessageUI吗? '@import MessageUI;' – liamnichols 2014-09-23 08:04:56

1

我不知道为什么这个工作。我不是调用此方法之前,但如果我被解雇viewControllers第一它的作品呈现任何其他viewControllers ...

[self dismissViewControllerAnimated:YES completion:^{ 
    [self presentViewController:picker animated:YES completion:^{}]; 
}]; 
+0

这不能解决我的问题。 – andygeers 2014-10-20 11:15:25

+0

这很奇怪!它也适用于我。 – 2014-11-14 22:33:34

0

有同样的问题,看起来像SDK8.0在iOS8中构建MFMailComposeController作为popOver,因此您必须关闭任何其他popOver。这是一个它如何工作的例子。

-(void)sendMail{ 
    [[[self fatherController] sharePopOver] dismissPopoverAnimated:YES]; 
    MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; 
    [controller setMailComposeDelegate:[self fatherController]]; 
    [[self fatherController] presentViewController:controller animated:YES completion:NULL]; 
} 
+0

这个问题也只发生在iPad上,因为没有在iPhone/iPod的弹出 – user2387149 2014-10-13 22:26:16

0

与UIActionSheet有同样的问题。当UIActionSheet存在时,MFMailComposeViewController不显示(仅在iOS 8上)。即使你在没有动画的情况下解雇它。等待1秒钟可以解决这个问题。所以我用UIAlertController(在iOS 8中引入)用于新设备,UIActionSheet用于旧设备。我现在有一个丑陋而且很长的代码,这要归功于Apple。

+1

嗨,我解决了使用UIActionSheet的问题。我把MFMailComposeViewController显示在另一个UIActionSheetDelegate回调函数中 - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex'。 – 2015-02-03 09:13:08

0

MailComposer不能在模拟器上工作,但它可以与设备(iOS 8)一起使用。

6

我在iOS 8上有类似的问题,在iOS 7和之前的工作正常。

我在用户按下UIActionSheet中的按钮后显示了我的MFMailComposeViewController。因此,在以前的实现,我把邮件撰写,并显示在MFMailComposeViewController功能UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 

这是与函数名称简单明了。

但是,也许是由于某些UI动画冲突引起的,同时显示MFMailComposeViewController和解除UIActionSheet使得MFMailComposeViewController未显示。

  • 解决方案

我的解决办法是把在UIActionSheetDelegate功能MFMailComposeViewController显示:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 

这是UIActionSheet动画完成后调用。

希望这可以帮助有同样问题的人。

+0

此修复程序在iOS 9.2中也适用于我 – 2016-01-28 02:31:07

0

在酥料饼FUNC只是做

@IBAction func exportAsMail(sender: AnyObject) { 

    NSNotificationCenter.defaultCenter().postNotificationName("exportAsMail", object: nil) 

    self.dismissViewControllerAnimated(false, completion: nil) 
    ///****animated have to be false not true 


} 
相关问题