2013-03-15 76 views
1

解僱在iOS 6中所提出的MFMailComposeViewController不會解散,如果用戶試圖發送第二封郵件......MFMailComposeViewController不會在iOS 6

一切完美的作品首次面世,併發送電子郵件。但是,如果再次選擇電子郵件選項,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,但它不起作用。

回答

5

您是否嘗試過在每次發送郵件時都創建一個新的MFMailComposeViewController?我不確定你是否應該重複使用它。

+0

應該叫我認爲這就是問題所在!一旦電子郵件發送並且用戶被帶回到呈現視圖控制器,是否有方法創建新的MFMailComposeViewController?我非常感謝快速回復和幫助。 – user2175392 2013-03-15 20:19:37

+0

是的,我的建議是在調用'setToRecipients'之前放置'mailComposeViewController = [[MFMailComposeViewController alloc] init];'。 – 2013-03-15 20:21:11

+0

太棒了。謝謝!我會嘗試第二次回到Mac。 – user2175392 2013-03-15 20:40:55

0

你可以試試這個:

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

- (空)mailComposeController:didFinishWithResult:錯誤:如果您分配類委託