Reputation: 1280
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
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
Reputation: 11476
I use the second format:
MFMailComposeViewController *mf = [[MFMailComposeViewController alloc] init];
Make sure:
MessageUI.framework
to your project#import <MessageUI/MessageUI.h>
to your class header fileMFMailComposeViewControllerDelegate
and any relevant methods you requireIf 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
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