Skip to content

Instantly share code, notes, and snippets.

@derrick-branch
Created July 22, 2015 19:34
Show Gist options
  • Save derrick-branch/e373732d127878a5eb59 to your computer and use it in GitHub Desktop.
Save derrick-branch/e373732d127878a5eb59 to your computer and use it in GitHub Desktop.
MFMailComposeViewController
// At top of ViewController implementation
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface ViewController () <MFMailComposeViewControllerDelegate>
@end
@implementation ViewController
- (void)sendEmail {
MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
vc.mailComposeDelegate = self;
// 1. Set Subject from template, personalized with Branch link & first name
NSString *firstName = [self.nameTextField.text componentsSeparatedByString:@" "][0];
[vc setSubject:[NSString stringWithFormat:self.currentTemplate[@"subject"], firstName]];
// 2. Set message from template
[vc setMessageBody:[self getMessageBodyWithFirstName:firstName
url:self.url
template:self.currentTemplate[@"body"]]];
// 3. Set recipient
[vc setToRecipients:[NSMutableArray arrayWithObject:self.emailAddressTextField.text]];
// 4. Pull up screen with email, ready to send!
[self presentViewController:vc animated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[controller dismissViewControllerAnimated:YES completion:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment