Skip to content

Instantly share code, notes, and snippets.

@chinedufn
Last active August 29, 2015 14:03
Show Gist options
  • Save chinedufn/3669589b4aee52b814b9 to your computer and use it in GitHub Desktop.
Save chinedufn/3669589b4aee52b814b9 to your computer and use it in GitHub Desktop.
Tapping a button to send an email on iOS 7
#import <MessageUI/MFMailComposeViewController.h>
/********** Later... *************/
//link your button up to this
- (void) buttonPressed:(id)(sender){
//if their device can send emails
if([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setToRecipients:@[];
[mailController setSubject:@"Interesting subject here"];
[mailController setMessageBody:@" ;) Some high conversion copy here ;) " isHTML:NO];
if(mailController){
[self presentViewController:mailController animated:YES completion:^{
//The view has been presented
}];
}
}
else{
//if their device cannot send emails
}
}
}
//later when they've sent an email
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
[self dismissViewControllerAnimated:controller completion:^{
if(result == MFMailComposeResultSent){
UIAlertView *thankYouForEmail = [[UIAlertView alloc] initWithTitle:@"We..." message:@"Love You" delegate:nil cancelButtonTitle:@"Wow Love You Too!" otherButtonTitles:nil, nil];
[thankYouForEmail show];
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment