2012-01-14 3 views
2

MFMailComposeViewController를 사용하여 내 응용 프로그램에서 메일을 보냅니다. 그러나 현재 메일 작성보기 컨트롤러, 모든 탐색 버튼을 사용할 수 없습니다 (선택 메일 주소 화면에서 뒤로 버튼 제외), 나는 홈 버튼을 사용하여 응용 프로그램을 종료해야합니다. 누구든지 아이디어가 있습니까? 여기 스크린 샷 : Screen shot 2MFMailComposeViewController 탐색 모음 단추가 비활성화되었습니다.


코드 :

 
- (void)shareVieEmail 
{ 
    if ([MFMailComposeViewController canSendMail]) { 
     MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; 
     mailViewController.mailComposeDelegate = self; 
     [mailViewController setSubject:@"Test subject"]; 
     [mailViewController setMessageBody:@"Mail message body" isHTML:NO]; 

     NSData *imageData = [NSData dataWithContentsOfFile:photourl]; 
     [mailViewController addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"example_photo"]; 
     [self presentModalViewController:mailViewController animated:YES]; 
    } else { 
     [[[UIAlertView alloc] initWithTitle:@"Cannot send mail" message:@"Device is unable to send email in its current state" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]; 
    } 
} 

위임 방법 :

 
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      //NSLog(@"Result: canceled"); 
      break; 
     case MFMailComposeResultSaved: 
      //NSLog(@"Result: saved"); 
      break; 
     case MFMailComposeResultSent: 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
      [alert show]; 
     } 
      break; 
     case MFMailComposeResultFailed: 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Failed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
      [alert show]; 
     } 
      break; 
     default: 
      //NSLog(@"Result: not sent"); 
      break; 
    } 
    if (error) { 
     [[[UIAlertView alloc] initWithTitle:@"Cannot send mail" message:[NSString stringWithFormat:@"ERROR:%@", [error userInfo]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]; 
    } 
    [self dismissModalViewControllerAnimated:YES]; 
} 

그리고 헤더 파일 , 나는 MFMailCompos을 구현 선언 eViewControllerDelegate.

+0

컨트롤러를 표시하는 데 사용 된 코드를 표시 할 수 있습니까? – mvds

+0

@mvds 코드를 올렸습니다. – youshunei

+0

이상합니다. 괜찮아 보입니다. 이메일 설정과 관련이 있습니까? 모든 기기에서 이렇게 보이나요? – mvds

답변

2

정확히 같은 문제가있었습니다. 그리고이 알아낼 걸 렸어요하지만 놀라운 그것이 내가에 내기 아래 정의 UIBarButtonItem

에 오지 당신의 UIBarButtonItem.h이 방법

-(void)setEnabled:(BOOL)enabled ; 

이며, 구현은 다음과 같습니다

-(void)setEnabled:(BOOL)enabled { 
    if (self.customView) { 
     if ([[self.customView.subviews objectAtIndex:0] isKindOfClass:[UIButton class]])   { 
      ((UIButton*)[self.customView.subviews objectAtIndex:0]).enabled = enabled; 
     } 
    } 
} 

이 방법으로 문제를 해결하면 즉시 문제가 발생하므로 문제가 해결되어야합니다.

+0

예! ^^. 너 맞아!, 고마워!. 나는이 방법을 다시 쓰겠습니다. 이 문제가 해결되었습니다. – youshunei

-1

MFMailComposeViewController의 대리자에서 didFinishWithResult:을 구현하고 거기에서 모달보기 컨트롤러를 닫아야합니다.

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    // you can test the result of the mail sending here if you want 

    [self dismissModalViewControllerAnimated:YES]; 
} 
+0

didFinishWithResult 대리자 메서드를 구현했습니다. – youshunei

0

나는 또한이 문제를했지만, CNContactViewController의 버그이 workaround 제안으로 내가 UINavigationController에서 setNavigationBarHidden:animated:을 무시했기 때문에 내 경우가 있었다. 해결 방법을 포함하고 MFMailComposeViewController의 문제를 해결할 수있는 한 가지 해결책은 현재의 클래스 인 topViewController에 따라 원본 메서드 나 재정의 된 메서드 중 하나를 호출 할 수 있도록 메서드를 사용하는 것입니다.