2014年7月29日火曜日

[iOS]メールを送信

- (void)sendMail
    if([MFMailComposeViewController canSendMail] == YES) { //メーラーが使用できるかどうか
        MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
        [controller setSubject:@"subject"]; //題名
        [controller setMessageBody:@"message" isHTML:NO]; //本文
        controller.mailComposeDelegate = self; //成功、失敗時にdelegateを送る
        [self presentViewController:controller animated:YES completion:nil]; //ViewContrllerとして立ち上げる
    }
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [self dismissViewControllerAnimated:YES completion:nil]; //終了時にViewContrllerを閉じる
    return;
}