アプリ内から標準メールを起動する

アプリ内から標準メールを起動するTipsです。
まずは、MesseageUI.frameworkを追加します。
そして、使いたい画面のヘッダファイルで読み込み設定。
#import <MessageUI/MessageUI.h> #import <MessageUI/MFMailComposeViewController.h>
※<>は半角です。
そして、カテゴリでMFMailComposeViewControllerDelegateを指定。
//メール送信 -(void)mailsousin{ MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; //メールタイトル設定 [picker setSubject:@"メールタイトルを入れます"]; //To,Cc,Bccを設定 NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; [picker setToRecipients:toRecipients]; [picker setCcRecipients:ccRecipients]; [picker setBccRecipients:bccRecipients]; // 添付ファイルをつけたい場合(画像の場合) NSData *data = [[[NSData alloc] initWithData:UIImagePNGRepresentation(uiimageを入れる)] autorelease]; [picker addAttachmentData:data mimeType:@"image/jpg" fileName:@"image"]; [self presentModalViewController:picker animated:YES]; [picker release]; }
あとは、メールを送りたいタイミングでmailsousinを呼び出せば、メール送信画面が立ち上がります。
[sc name=”ios”][sc name=”engeneer”]
SPONSER
SHARE
YouTube
PROFILE
