Чтение Sending mail with MFMailComposeViewController
Сначала включите среду MessageUI и внедрите MFMailComposeViewControllerDelegate.
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface MainViewController : UIViewController <MFMailComposeViewControllerDelegate> {
}
затем реализуйте метод, подобный этому, и метод делегата для удаления почтового контроллера.
- (IBAction)pressentMailController:(id)sender {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Test subject!"];
// Set up the recipients.
/*NSArray *toRecipients = [NSArray arrayWithObjects:@"first@example.com",
nil];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com",
@"third@example.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObjects:@"four@example.com",
nil];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
*/
// Attach an image to the email.
/*NSString *path = [[NSBundle mainBundle] pathForResource:@"ipodnano"
ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png"
fileName:@"ipodnano"];
*/
// Fill out the email body text.
NSString *emailBody = @"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
// Present the mail composition interface.
[self presentModalViewController:picker animated:YES];
[picker release]; // Can safely release the controller now.
}
// The mail compose view controller delegate method
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES];
}
Код позволяет добавлять получателей, тело, тему и вложения. Раскомментируйте строки по мере необходимости.
