0

I am not sure if I understand MFMailComposeViewController correctly. I am expecting a viewcontroller with an existing view to show up on my screen. I can see the FTViewController's view. But the mail composer never appears.

I have simplified the original question to a bare minimum.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.

        FTViewController *vc = [[FTViewController alloc]init];
        self.window.rootViewController = vc;
    ..
    }

In FTViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    FTTest *test = [[FTTest alloc] init];
    [test testmeup];
}

FTTest:

#import <MessageUI/MessageUI.h>

@interface FTTest : UIViewController <MFMailComposeViewControllerDelegate>

@implementation FTTest

- (void)testmeup
{
    BOOL ok = [MFMailComposeViewController canSendMail];
    if (!ok)
        return;
    MFMailComposeViewController* vc = [MFMailComposeViewController new];
    vc.mailComposeDelegate = self;
    [self presentViewController:vc animated:YES completion:nil];
}
Houman
  • 64,245
  • 87
  • 278
  • 460
  • 1
    Try checking if you can even send mail (it might not be configured) before presenting the view controller. You can also use it as a debug to tell you if that's the problem. [canSendMail](https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html#//apple_ref/occ/clm/MFMailComposeViewController/canSendMail) – hukir Nov 27 '13 at 01:46
  • is there any email account in your mail? – chancyWu Nov 27 '13 at 02:56

2 Answers2

1

I finally found the solution to my problem.

If I move the same code from - (void)viewDidLoad to an action-able method, it works like a charm. Hence the user needs to press a button or take an action first for this to work.

- (IBAction)gogogo:(id)sender
{
    FTTest *test = [[FTTest alloc] init];
    [test testmeup];
}

I believe Apple has done this to make sure the user knows what emails are being sent out. Originally I was going to utilize this approach for catching exceptions and send them via email to myself as explained in this solution here.

Maybe I am overlooking something, feel free to comment.

Community
  • 1
  • 1
Houman
  • 64,245
  • 87
  • 278
  • 460
  • Exactly the same as what I said in the comment on my other answer; you were simply calling `testmeup` way too early. In `viewDidLoad`, just as in `application:didFinish...`, there is no interface yet. It's as simple as that. – matt Nov 27 '13 at 17:10
0

Is there any email account in your Mail? if all accounts are disabled or removed

[MFMailComposeViewController canSendMail] 

returns NO, then Nothing come out.

chancyWu
  • 14,073
  • 11
  • 62
  • 81