Created
October 14, 2014 09:30
-
-
Save AlexHedley/d326c1efbd1830d33a48 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
| //http://www.appcoda.com/ios-programming-101-send-email-iphone-app/ | |
| - (IBAction)sendEmail:(id)sender { | |
| // Email Subject | |
| NSString *emailTitle = @"iOS Email"; | |
| // Email Content | |
| NSString *messageBody = @"Sent from iOS App"; | |
| // To address | |
| NSArray *toRecipents = [NSArray arrayWithObject:@"unpluggedne@gmail.com"]; | |
| MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; | |
| mc.mailComposeDelegate = self; | |
| [mc setSubject:emailTitle]; | |
| [mc setMessageBody:messageBody isHTML:NO]; | |
| [mc setToRecipients:toRecipents]; | |
| //[[mc navigationBar] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName]]; | |
| [[mc navigationBar] setTintColor:[UIColor whiteColor]]; | |
| // Present mail view controller on screen | |
| [self presentViewController:mc animated:YES completion:^{ | |
| [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; | |
| }]; | |
| //[self applyComposerInterfaceApperance]; | |
| } | |
| - (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error | |
| { | |
| switch (result) | |
| { | |
| case MFMailComposeResultCancelled: | |
| NSLog(@"Mail cancelled"); | |
| break; | |
| case MFMailComposeResultSaved: | |
| NSLog(@"Mail saved"); | |
| break; | |
| case MFMailComposeResultSent: | |
| NSLog(@"Mail sent"); | |
| break; | |
| case MFMailComposeResultFailed: | |
| NSLog(@"Mail sent failure: %@", [error localizedDescription]); | |
| break; | |
| default: | |
| break; | |
| } | |
| // Close the Mail Interface | |
| [self dismissViewControllerAnimated:YES completion:NULL]; | |
| } | |
| - (void)applyComposerInterfaceApperance | |
| { | |
| [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; | |
| [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}]; | |
| [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment