MFMailComposeViewController不会在iOS 6上解散

use*_*392 1 objective-c ios6

在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];
}
Run Code Online (Sandbox Code Playgroud)

然后这个:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

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

Jes*_*sak 5

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