1

在 iOS 6 中,MFMailComposeViewController如果用户尝试发送第二封电子邮件,则呈现的内容不会消失...

一切正常,第一次运行并发送电子邮件。但是,如果再次选择电子邮件选项MFMailComposeViewController,取消时不会关闭。

以下是我的实现方式:

- (IBAction)buttonEmailClick:(id)sender {
    if (![MFMailComposeViewController canSendMail]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Can't send" message:@"This device is unable to send emails." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        return;
    }
    NSDictionary *contactsInfo = [self contactsInfoFromPlistNamed:kConfigPlistName];
    [mailComposeViewController setToRecipients:[NSArray arrayWithObject:[contactsInfo objectForKey:@"email"]]];
    //[mailComposeViewController setSubject:kEmailDefaultSubject];
    //[mailComposeViewController setMessageBody:text isHTML:NO];
    [self presentModalViewController:mailComposeViewController animated:YES];
}

然后这个:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    UIAlertView *alert = nil;
    if (result == MFMailComposeResultSent) {
        alert = [[UIAlertView alloc] initWithTitle:@"Sent" message:@"Your email was sent." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    }
    else if (result == MFMailComposeResultFailed) {
        alert = [[UIAlertView alloc] initWithTitle:@"Failed" message:@"An error occured and your email was not sent." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    }

    [alert show];
    [self dismissModalViewControllerAnimated:YES];
}

它在 iOS 5 中运行良好,但在 iOS 6 中不行。我尝试用 iOS 6 的非弃用方法替换,但它不起作用。

4

2 回答 2

5

您是否尝试过在他们每次发送电子邮件时创建一个新的 MFMailComposeViewController?我不确定你是否应该重复使用它。

于 2013-03-15T20:08:19.887 回答
0

你可以试试这个:

MFMailComposeViewController * composer = [[MFMailComposeViewController alloc] init];
composer.delegate = self;

-(void)mailComposeController:didFinishWithResult:error: 如果您将该类分配给委托,则应调用

于 2013-07-26T18:46:37.497 回答