2011-02-01 9 views
0

내 응용 프로그램에 MFMailComposeViewController를 구현 중입니다. 다음 코드를 사용하여 메일 작성기를 열려고하면 "잡히지 않는 예외 'NSInvalidArgumentException'으로 인해 응용 프로그램이 종료되는 것과 같은 예외가 발생합니다. 이유 : '응용 프로그램이 대상에 nil 모달보기 컨트롤러를 표시하려고했습니다.' 내가 뭘 잘못했는지 모르겠다. 너희들은 내 다음 코드를보고 나를 제안 해 주시겠습니까.PresentModalViewController를 시도 할 때 예외 발생

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil ]; 

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; 
controller.mailComposeDelegate =self ; 
controller.delegate=self; 
[email protected]"Title"; 
[controller setSubject:@"See my Notes"]; 
NSArray* toRecipients=nil; 

[controller setToRecipients:toRecipients]; 

NSString *emailBody = @""; 
emailBody = @"<html><head><title><style type=\"text/css\">a {color: red}</style>"; 
emailBody = [emailBody stringByAppendingString:@"</title></head><body style='background-color: transparent;color:black'> "]; 
emailBody = [emailBody stringByAppendingString:@"Hello all"]; 
emailBody = [emailBody stringByAppendingString:@"</body></html>"]; 
[controller setMessageBody:emailBody isHTML:YES]; 

[self presentModalViewController:controller animated:YES]; 

미리 감사드립니다. -Sek.

답변

1

음 ... 전자 메일 클라이언트가 구성되지 않은 기기에서 이메일을 보낼 때 유사한 문제가 발생했습니다 (하지만 시뮬레이터에서는 문제가 아닙니다).

당신은 이런 이런 경우를 테스트 할 수 ...

// viewWillAppear

if (![MFMailComposeViewController canSendMail]) sendEmailButton.enabled = NO;

관련 문제