Created
July 22, 2015 19:34
-
-
Save derrick-branch/e373732d127878a5eb59 to your computer and use it in GitHub Desktop.
MFMailComposeViewController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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