0

I can't create MFMailComposeViewController's object. Can you help me?

I've tried 2 methods and it doesn't work:

MFMailComposeViewController *mf = [MFMailComposeViewController new];

or

MFMailComposeViewController *mf = [[MFMailComposeViewController alloc] init];

Anybody knows what's happen? Thanks.

P.S. It doesn't work on iPad 2 with ios 4.3.3, but it work on iPad 1 with ios 4.3.2

1
  • 1
    And what you are doing after this line?
    – EmptyStack
    Nov 25, 2011 at 8:55

3 Answers 3

4

Check to see if [MFMailComposeViewController canSendMail] (documentation linked) returns YES.

I suspect it's not, in your case.

If it does return yes, is "mf" set to null after you do alloc/init ?

Also make sure the MessageUI.framework is added to your project. In case you need it, here's a tutorial.

0
2

I use the second format:

MFMailComposeViewController *mf = [[MFMailComposeViewController alloc] init];

Make sure:

  • You have added the MessageUI.framework to your project
  • You have added #import <MessageUI/MessageUI.h> to your class header file
  • You declare MFMailComposeViewControllerDelegate and any relevant methods you require

If the device does not have any mail accounts setup when you create and later call [self presentModalViewController:mf animated:YES]; then you'll get an Apple alert view informing you of the situation.

1
  • Seems to crash if you don't have that on iOS 6.1
    – powerj1984
    Jun 11, 2013 at 13:47
1

1)Add MessageUI.framework to your project

2)import #import to ur view controller

3)declare MFMailComposeViewControllerDelegate methods

        MFMailComposeViewController *mail = [[MFMailComposeViewController alloc]init];
        mail.mailComposeDelegate = self;
        [mail setToRecipients:[NSArray arrayWithObjects:@"mail id", nil]];
        [mail setSubject:@"Contact Us"];
        [mail setMessageBody:@"If U want any information u can send the mail <div> " isHTML:YES];
        [self presentViewController:mail animated:YES completion:nil];
        [mail release];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.