我有一個調用MFMailComposeViewController的按鈕。有時候,當我點擊「刪除草稿」時,應用程序崩潰,但有時會正確地解除視圖。我可以'明白爲什麼。這裏是我的代碼:當按下「刪除草稿」時MFMailComposeViewController崩潰
- (IBAction)openEmail:(id)sender {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = (id)self;
NSArray *myEmail = [[NSArray alloc] initWithObjects:@"[email protected]", 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];
}
誰能幫助我?