2010-03-11 9 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, 어리석은! 왜 애플은 대리인을 위해 비표준 명명 규칙을 사용하게 될까요? 그래도 문제가 해결되었습니다. –

+0

UINavigationController를 하위 클래스 화하기 때문에 대리자가 이미 사용되었습니다. –

+0

+1이 나를 잡았으므로 가장 확실한 해결책은 아닙니다. – davbryn

관련 문제