I have ViewController with button, and action on button:
- (IBAction)clickMe:(id)sender {
MailHelper *helper = [[MailHelper alloc] init];
[helper setAllData:self];
}
Also, there is helper class for mail composing (MailHelper.h):
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface MailHelper : UIViewController<MFMailComposeViewControllerDelegate>
@property MFMailComposeViewController* mailView;
- (void)setAllData:(UIViewController *)ctrl;
@end
and implementation (MailHelper.m):
- (void)setAllData:(UIViewController *)ctrl {
mailView = [[MFMailComposeViewController alloc] init];
mailView.mailComposeDelegate = self;
mailView.toRecipients = @[@"[email protected]"];
[mailView setSubject:@"Subject"];
[ctrl presentViewController:mailView animated:YES completion:nil];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];
}
I can open mail composer, but while sending mail, saving draft or deleting draft app crashes. Any ideas?
Ok guys. Solution is to make instance of helper somewhere else, let's say:
@implementation ViewController
MailHelper *helper;
and:
- (IBAction)clickMe:(id)sender {
helper = [[MailHelper alloc] init];
[helper setAllData:self];
}