iPhone MFMAilComposeViewControllerDelegate problem - iphone

I wrote a code that utilizes the MFMAilComposibleViewController to harness in-app emails. I specified the delegate as so under, but my delegate method isn't getting called. This is the first time I'm getting this type of error; I normally develop under the iPhone but for a client I need to develop under an iPad.
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setModalPresentationStyle: UIModalPresentationFormSheet];
[mailComposer setSubject: #"Hello World"];
[mailComposer setMailComposeDelegate: self];
[mailComposer setMessageBody: #"<font color='red'>Hello</font> <font color='blue'>World</font>" isHTML:YES];
[self presentModalViewController: mailComposer animated: YES];
This snippet is an exact copy-paste of the method that calls the mailview. Please note, I did specify in my header the MFMailViewControllerDelegate protocol.
Thank You!

Have you tested this in simulator? As i've experienced before, the mail composer doesn't work in the simulator but in the device. Try it.

Related

SMS through Iphone, MFMessageComposeViewController

I am trying to send sms through device. But it crashes on the line
[self presentModalViewController:picker animated:YES];
CODE:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.recipients = rec; // your recipient number or self for testing
picker.body = billInfo;
[self presentModalViewController:picker animated:YES];
[picker release];
Error Log:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <billSummary: 0xfc7e780>.'
Have you checked +[MFMessageComposeViewController canSendText]? From the docs,
Before using this class, you must always check to see if the current device is configured to send SMS messages by calling the canSendText class method. If the user’s device is not set up for the delivery of SMS messages, you can notify the user or simply disable the SMS features in your application. You should not attempt to use this interface if the canSendText method returns NO.
Other reasons it might not work:
No SIM card?
Device isn't running iOS 4.
Device is an iPod Touch/iPad.
"Device" is actually the simulator.
[self presentModalViewController:picker.view animated:YES];
<MFMessageComposeViewControllerDelegate>
should be added in the .h of your class.
MFMessageComposeViewController is the subclass of UINavatigationController.
so apply pushViewController instead of presentmodalviewController

Sending email through iPhone application

I'd like to setup a button in the iPhone app I'm making to send an email with the results of some operations performed earlier in the app. I've read other people comment on here that you can use other frameworks but, frankly, I can't find one that actually works. I've heard MailCore is good. Has anyone been able to send an email seamlessly through an iPhone app?
Note: I do not want to exit the app to send the email.
Answer From this Question: How can I send mail from an iPhone application
On iPhone OS 3.0 and later you should use the MFMailComposeViewController class, and the MFMailComposeViewControllerDelegate protocol, that that tucked away in the MessageUI framework. Note you must link the Message UI Framework and import its headers.
#import <MessageUI/MFMailComposeViewController.h>
First to send a message:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"My Subject"];
[controller setMessageBody:#"Hello there." isHTML:NO];
if (controller) [self presentModalViewController:controller animated:YES];
[controller release];
Then the user does the work and you get the delegate callback in time:
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;{
if (result == MFMailComposeResultSent) {
NSLog(#"It's away!");
}
[self dismissModalViewControllerAnimated:YES];
}
In this case, your best bet is to use a service like Amazon Simple Email Service (SES). It will enable you to send the email without ever leaving the application (unlike the other solutions listed). Amazon AWS has an iOS SDK which can utilize the SES service. This service is super simple to use, and the cost is extremely low.
http://aws.amazon.com/sdkforios/
MFMailComposeViewController *mailComposer =[[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
NSString *emailBody = #"Write email body text here........";
[mailComposer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];

MFMailComposeViewController in iphone app

hii every one
can we use " MFMailComposeViewController " with out using " presentModalViewController" , i mean i need to send email with out navigating to that mail composer page
i did a test project with following code
- (IBAction)buttonPressed {
arrRecipients = [[NSMutableArray alloc]init];
[arrRecipients addObject:#"xxxxxxx#gmail.com"];
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setSubject:#"Ravikiran test mail"];
[mailController setToRecipients:arrRecipients];
[mailController setMessageBody:#"this is my test app" isHTML:YES];
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
it is sending mail but it is navigating to mail composer page & then its sending but i need to send mail just on click of the button
No, you cannot use MFMailComposeViewController to send an email without user interaction. There are probably 3rd parties libraries that let you do this, but the iOS SDK does not allow you to.
Also, you're leaking the arrRecipients array.
Best way for your needs is to have a web service which sends the data to an email id.
its always to good to inform the user in some way before sending the mail.
Thanks!

Email body not displayed after sending from iPhone via code

I have couple of iPhone apps that sends an email via code.
I've noticed quite a number of emails coming in from customers where everything is populated except for the body message (i always see their signature though).
I sent a test message, using the same app from my iPhone device, and i get the message (a simple "this is a test" message).
Wondering if there are any coding that needs to occur to handle different version of iOS, or perhaps different iPhone device hardwares?
Anybody noticed this before?
I would consider the possibility that the users are accidentally pressing send on a blank email. Perhaps to eliminate this as a possibility, guard against blank messages in code, then if it still happens you'll know it's a real issue.
set all delegates properly
and use this
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSString *sub= [NSString stringWithFormat:#"The Black Sheep App: %# Specials",[[BarSplArr objectAtIndex:0]objectForKey:#"barname"]];
NSString *message=[NSString stringWithFormat:#"Check out these specials for %# on %#, %# \n\n %#",[[BarSplArr objectAtIndex:0]objectForKey:#"barname"],day,date,[[BarSplArr objectAtIndex:0]objectForKey:#"drinkspecials"] ];
[controller setSubject:sub];
[controller setMessageBody:message isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];

Easy way to open the Mail application with an pre-defined message subject and body?

In my app the user generates text content. I want to enable the user to launch the Mail application, which then should contain a specified subject and message body. Like: You write a poem in my app and then want to send it to your new girlfriend. So you tap a mail icon and the Mail app opens, containing already an subject and message body with your poem inside.
Someone said there is a kind of URL mechanism for that?
You can use MFMailComposeViewController for sending the mail.
-(void)OpenMail{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"my new poem"];
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
emailBody is string which contains the poem.
All the best.
Apple URL Scheme Reference: Mail Links lists all your options.
Or you use MFMailComposeViewController.