Last active
August 29, 2015 13:57
-
-
Save Adnan1990/9460335 to your computer and use it in GitHub Desktop.
IOS Email Composing Using MessageUI Framework
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
| #import <UIKit/UIKit.h> | |
| #import <MessageUI/MessageUI.h> | |
| @interface ViewController : UIViewController | |
| @end |
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
| #import "ViewController.h" | |
| @interface ViewController () <MFMailComposeViewControllerDelegate, UITextFieldDelegate, UITextViewDelegate> | |
| @property (nonatomic, weak) IBOutlet UITextField *subject; | |
| @property (nonatomic, weak) IBOutlet UITextView *messageBody; | |
| @property (nonatomic, weak) IBOutlet UIButton *mailButton; | |
| @end | |
| @implementation ViewController | |
| - (void)viewDidLoad | |
| { | |
| [super viewDidLoad]; | |
| // Do any additional setup after loading the view, typically from a nib. | |
| self.subject.delegate = self; | |
| self.messageBody.delegate = self; | |
| } | |
| - (void)didReceiveMemoryWarning | |
| { | |
| [super didReceiveMemoryWarning]; | |
| // Dispose of any resources that can be recreated. | |
| } | |
| - (IBAction)sendMail { | |
| MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; | |
| picker.mailComposeDelegate = self; | |
| [picker setSubject:self.subject.text]; | |
| // NSString *pageLink = @"http://ioscreator.com"; | |
| // NSString *emailBody = [NSString stringWithFormat:@"Sent from %@", pageLink]; | |
| [picker setMessageBody:self.messageBody.text isHTML:YES]; | |
| picker.navigationBar.barStyle = UIBarStyleBlackTranslucent; | |
| [self presentViewController:picker animated:YES completion:NULL]; | |
| } | |
| - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error | |
| { | |
| [self dismissViewControllerAnimated:YES completion:NULL]; | |
| } | |
| - (BOOL)textFieldShouldReturn:(UITextField *)textField | |
| { | |
| [textField resignFirstResponder]; | |
| return YES; | |
| } | |
| //- (void)textViewDidEndEditing:(UITextView *)textView; | |
| //{ | |
| // [textView resignFirstResponder]; | |
| //} | |
| - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text | |
| { | |
| self.messageBody.text = textView.text; | |
| if ([text isEqualToString:@"\n"]) { | |
| [textView resignFirstResponder]; | |
| return NO; | |
| } | |
| return YES; | |
| } | |
| @end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Showing IOS email dialog for Sending Email