I am trying to open email composure in iOS 9 and send option is not working. I have downloaded some project they also have the same problem with ios 9.
I have declared globalMailComposer
in app delegate .h and this code is in app delegate .m file in a alert buton
if ([MFMailComposeViewController canSendMail])
{
globalMailComposer = [[MFMailComposeViewController alloc] init];
self.globalMailComposer.mailComposeDelegate = self;
NSString *emailTitle = @"Test Email";
NSString *messageBody = @"iOS programming is so fun!";
NSArray *toRecipents: [NSArrayarrayWithObjects:@"[email protected]",nil];
[globalMailComposer setSubject:emailTitle];
[globalMailComposer setMessageBody:messageBody isHTML:NO];
[globalMailComposer setToRecipients:toRecipents];
[self.window.rootViewControllerpresentViewController:globalMailComposer animated:YES completion:nil];
}
- (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;
}
[self.window.rootViewController dismissViewControllerAnimated:YES completion:NULL];
}
AppDelegate.h
#import <UIKit/UIKit.h>
@import MessageUI;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) MFMailComposeViewController *globalMailComposer;
@end
AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate () <MFMailComposeViewControllerDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([MFMailComposeViewController canSendMail])
{
self.globalMailComposer = [[MFMailComposeViewController alloc] init];
self.globalMailComposer.mailComposeDelegate = self;
NSString *emailTitle = @"Test Email";
NSString *messageBody = @"iOS programming is so fun!";
[self.globalMailComposer setSubject:emailTitle];
[self.globalMailComposer setMessageBody:messageBody isHTML:NO];
[self.globalMailComposer setToRecipients:@[@"[email protected]"]];
[self.window.rootViewController presentViewController:self.globalMailComposer animated:YES completion:nil];
}
return YES;
}
- (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;
}
[self.window.rootViewController dismissViewControllerAnimated:YES completion:NULL];
}
@end