2010-03-11 55 views
2

我正在嘗試向我的應用程序添加電子郵件功能。我可以讓MFMailComposeViewController正確顯示並預先填充其主題和正文,但由於某些原因,當用戶單擊導航欄中的「取消」或「發送」按鈕時,應用程序就會掛起。我在第一行mailComposeController"didFinishWithResult:error中插入了一條NSLog()語句,它甚至不會將該行輸出到控制檯。MFMailComposeViewController掛起我的應用程序

有沒有人有一個想法是什麼會導致MFMailComposeViewController像這樣掛?

這裏是頭我的代碼:

#import "ManagedObjectEditor.h" 
#import <MessageUI/MessageUI.h> 

@interface MyManagedObjectEditor : ManagedObjectEditor 
    <MFMailComposeViewControllerDelegate, UIImagePickerControllerDelegate, 
    UINavigationControllerDelegate> { 
} 

- (IBAction)emailObject; 
@end 

從實現文件:

if ([MFMailComposeViewController canSendMail]) {   
    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init]; 
    mailComposer.delegate = self; 
    [mailComposer setSubject:NSLocalizedString(@"An email from me", 
               @"An email from me")]; 
    [mailComposer setMessageBody:emailString 
          isHTML:YES]; 
    [self presentModalViewController:mailComposer animated:YES]; 
    [mailComposer release]; 
} 
[error release]; 
[emailString release]; 

這裏是代碼從回調:

#pragma mark - 
#pragma mark Mail Compose Delegate Methods 
- (void)mailComposeController:(MFMailComposeViewController *)controller 
      didFinishWithResult:(MFMailComposeResult)result 
         error:(NSError *)error { 
    NSLog(@"in didFinishWithResult:"); 
    switch (result) { 
     case MFMailComposeResultCancelled: 
      NSLog(@"cancelled"); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"saved"); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"sent"); 
      break; 
     case MFMailComposeResultFailed: { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error sending email!",@"Error sending email!") 
                  message:[error localizedDescription] 
                  delegate:nil 
                cancelButtonTitle:NSLocalizedString(@"Bummer",@"Bummer") 
                otherButtonTitles:nil]; 
      [alert show]; 
      [alert release]; 
      break; 
     } 
     default: 
      break; 
    } 
    [self dismissModalViewControllerAnimated:YES]; 
} 

謝謝!

回答

6

我也得到了這一點,你需要設置mailComposeDelegate,而不是委託。

+0

omg,多麼愚蠢!蘋果爲什麼會爲代表使用非標準的命名約定!?!?? 雖然修正了這個問題! – 2010-03-11 19:44:50

+0

由於它是UINavigationController的子類,因此已經使用委託。 – 2010-03-11 19:50:32

+0

+1,因爲這也引起了我的興趣,並不是最明顯的解決方案。 – davbryn 2010-06-15 11:32:48