Sveta
Sveta

Reputation: 1280

I can't create MFMailComposeViewController's object

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

Upvotes: 0

Views: 1413

Answers (3)

Madhu
Madhu

Reputation: 2593

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];

Upvotes: 1

Luke
Luke

Reputation: 11476

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.

Upvotes: 2

Michael Dautermann
Michael Dautermann

Reputation: 89509

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.

Upvotes: 4

Related Questions