iOS6:MFMailComposeViewController未显示

时间:2013-06-19 11:24:29

标签: ios objective-c mfmailcomposeviewcontroller

MFMailComposeViewController没有在ios 6中呈现,而相同的代码在ios 6中工作,我的代码是

   if ([MFMailComposeViewController canSendMail])
   {
       searchView.hidden=YES;
       MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
       picker.mailComposeDelegate = self;
       [picker setSubject:[NSString stringWithFormat:@"Query from ccc App"]];
       NSArray *toarr =[[NSArray alloc]initWithObjects:@"ccc-connections@ccc.edu", nil];
       [picker setToRecipients:toarr];
       [self presentModalViewController:picker animated:YES];          
   }

2 个答案:

答案 0 :(得分:1)

presentModalViewController:animated:已在iOS 6.0中弃用。

改为使用presentViewController:animated:completion:

答案 1 :(得分:1)

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitel];
[mc setMessageBody:message isHTML:NO];
[mc setToRecipients:empfaenger];

[self presentViewController:mc animated:YES completion:NULL];

}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {

switch (result) {
    case MFMailComposeResultCancelled:
        NSLog(@"Email cancelled");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Email failed with error: %@", [error localizedDescription]);
        break;
    case MFMailComposeResultSaved:
        NSLog(@"Email saved");
        break;
    case MFMailComposeResultSent:
        NSLog(@"Email sent");
        break;
    default:
        break;
}

[self dismissViewControllerAnimated:YES completion:NULL];

}