我有一个调用 MFMailComposeViewController 的按钮。有时,当我单击“删除草稿”时,应用程序会崩溃,但有时它会正确关闭视图。我不明白为什么。这是我的代码:
- (IBAction)openEmail:(id)sender {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = (id)self;
NSArray *myEmail = [[NSArray alloc] initWithObjects:@"me@gmail.com", nil];
[composer setToRecipients:myEmail];
[self presentViewController:composer animated:YES completion:nil];
[[composer navigationBar] setTintColor:[UIColor colorWithRed:0.843 green:0.435 blue:0.435 alpha:1]];
}
else {
}
}
这个方法:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail send");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed");
break;
default:
NSLog(@"Mail not sent.");
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
谁能帮我?