2011-02-01 18 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;

関連する問題