2011-03-04 8 views
0

sendMail 버튼을 누르면 메일 버튼으로 이동하지만 보내거나 취소하면 애플리케이션으로 돌아 가지 않습니다. 어떤 제안?iPhone App Email 문제

-(IBAction)sendMail { 

    MFMailComposeViewController *mailComposer = [[[MFMailComposeViewController alloc] init] autorelease] ; 

    if ([MFMailComposeViewController canSendMail]) { 
     [mailComposer setToRecipients:nil]; 
     [mailComposer setSubject:nil]; 
     [mailComposer setMessageBody:@"Default text" isHTML:NO]; 

     [self presentModalViewController:mailComposer animated:YES]; 
    } 
} 

답변

1

은 케니가 제시 그런 다음 대리자 메서드를 구현 메일 작곡가 초기화

mailComposer.mailComposeDelegate = self;//very important if you want feedbacks on what the user did with your email sheet. 

아래에 다음 줄을 추가합니다. 이 메서드를 사용하여 사용자 지정 동작을 수행 할 수 있습니다.

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
// Notifies users about errors associated with the interface 
switch (result) 
{ 
case MFMailComposeResultCancelled: 
    { 
     //Do something, If you need to 
    } 
break; 

default: 
break; 
} 
[self dismissModalViewControllerAnimated:YES]; 
} 

것은 계속 문제가 발생하는 경우

@interface YourViewController : UIViewController <MFMailComposeViewControllerDelegate> { } 

을 추가하여 위임을 준수하는 것을 잊지 마십시오, 당신은 모든 것이 잘 설명 다음 자습서를 방문 할 수 있습니다 : http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/

4

대리인을 설정해야합니다 (일반적으로 MFMailComposeViewController를 표시 한보기 컨트롤러와 동일). 그런 다음 사용자가 저장 또는 취소 버튼을 누르면 MFMailComposeViewController는 대리자에 대해 -mailComposeController : didFinishWithResult : error를 호출합니다. 그래서 대리인으로 자신을 설정하고 다음과 같은 방법 정의 :

#pragma mark - 
#pragma mark MessageUI Delegate Methods 

- (void)mailComposeController:(MFMailComposeViewController*)controller 
      didFinishWithResult:(MFMailComposeResult)result 
         error:(NSError*)error { 

    [controller dismissModalViewControllerAnimated:YES]; 
} 
+0

에서 검증. – Vikings

+0

작성 컨트롤러를 초기화 할 때 composeController.delegate = self; –

1

이 멋진 라인 :

mailComposer.mailComposeDelegate = self; 

은 그 일이 잘못되었다는 것을 알지 못하고 며칠 동안 일하게 만들었습니다.

그리고 그들을 잊지 마세요 : 프로젝트에 MessageUI.framework을 가져올뿐만 아니라

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

.

내가 대리인으로 자신을 설정하여 무슨 뜻 이죠,이 코드 만 같은 문제에 연결 iOS5를