Skip to content

Instantly share code, notes, and snippets.

@Adnan1990
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save Adnan1990/9460335 to your computer and use it in GitHub Desktop.

Select an option

Save Adnan1990/9460335 to your computer and use it in GitHub Desktop.
IOS Email Composing Using MessageUI Framework
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController
@end
#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
@Adnan1990
Copy link
Author

Showing IOS email dialog for Sending Email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment