メールを送信するためのモーダルビューを開くシンプルなアプリがあります。Xcode4.2とiOS5を使用しており、iOSSimulatorでテストしています。キャッチされない例外「NSInvalidArgumentException」が原因でアプリが終了するとアプリがクラッシュし
ます。理由:
「アプリケーションがターゲットにnilモーダルビューコントローラーを提示しようとしました。」
行を実行するとき:
[self presentModalViewController:mailComposer animated:YES];
オブジェクト'mailComposer'を初期化しましたが。
クラスcom_FirstViewController.m:
#import "com_FirstViewController.h"
...
@implementation com_FirstViewController
....
....
-(void)showEmailComposer {
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
if ([mailClass canSendMail]) {
NSLog(@"showEmailComposer: Calling displayComposerSheet");
[self displayComposerSheet];
} else {
NSLog(@"showEmailComposer: Calling launchMailAppOnDevice");
[self launchMailAppOnDevice];
}
}
else {
NSLog(@"showEmailComposer: Calling launchMailAppOnDevice");
[self launchMailAppOnDevice];
}
}
#pragma mark -
#pragma mark Compose Mail
-(void) displayComposerSheet {
mailComposer = [[MFMessageComposeViewController alloc] init];
mailComposer.messageComposeDelegate = self;
// Set the mail title
[mailComposer setTitle:@"Mail Title"];
// Set the recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"user@company.com"];
[mailComposer setRecipients:toRecipients];
// EMail Body
NSString *mailBody = @"This is the mail body";
[mailComposer setBody:mailBody];
NSLog(@"present the modal view ctlr");
[self presentModalViewController:mailComposer animated:YES];
}
...
...
何かポインタをお願いしますか?