2012-10-05 55 views
1

我已經更新XCode到4.5,現在電子郵件功能崩潰,如果我按下按鈕發送電子郵件。IOS 6 Xcode 4.5 MFMailComposer崩潰

我做錯了什麼?

我已經實現了MessageUI.framework在我的頭文件

#import <UIKit/UIKit.h> 
#import <MessageUI/MessageUI.h> 

@interface ImpressumViewController : UIViewController <MFMailComposeViewControllerDelegate> 

這裏是我的按鈕代碼:

- (IBAction)kontakt:(id)sender { 

    MFMailComposeViewController *mailcontroller = [[MFMailComposeViewController alloc] init]; 
    [mailcontroller setMailComposeDelegate:self]; 
    NSString *email [email protected]"[email protected]"; 
    NSArray *emailArray = [[NSArray alloc] initWithObjects:email, nil]; 
    [mailcontroller setToRecipients:emailArray]; 
    [mailcontroller setSubject:@"Youtube Tutorials"]; 
    [self presentViewController:mailcontroller animated:YES completion:nil]; } 

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 



    } 
+0

不確定,但嘗試[self presentModalViewController:composer animated:YES completion:nil]; (增加了「Modal」) – Romo

+0

嗨,謝謝你的回答。但這不起作用。我認爲莫代爾是舊版本 – user1355961

+0

完全相同的代碼適用於我 –

回答

0

你需要編寫遵循此委託方法的代碼

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued"); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Mail saved: you saved the email message in the Drafts folder"); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send the next time the user connects to email"); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error"); 
      break; 
     default: 
      NSLog(@"Mail not sent"); 
      break; 
    } 

    //[self dismissModalViewControllerAnimated:YES]; 
}