Mail comes Without Message content using MFMailComposeViewController in iPhone - iphone

I have faced some problems, when the user sent the mail. Some of the time the mail comes without message content(Email body), even the user typed the message content.The message content doesn't displayed only some times.(For 10 mail comes into my inbox, 2 or 3 messages comes without content in the email body) So please guide me why its happening?
Here my code is,
- (void)viewDidLoad {
[self displayComposerSheet];
}
-(void) displayComposerSheet
{
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[picker setToRecipients:[NSArray arrayWithObjects:#"aaa#bbb.com",nil]];
[picker setSubject:#"ShoutOuts"];
}
[self presentModalViewController:picker animated:YES];
}
Please Help me Out.
Thanks!

I don't have a straight answer, but two hints:
a) Why are you calling displayComposerSheet in viewDidLoad? I'd rather put it into viewWillAppear, since the view controller might already be loaded and in memory if used once again.
b) Did you try pre-filling the mail body with a placeholder text to see if that is being sent?

Related

Obj C Modal box with options to call or email

Hi everyoneI need some direction on how to go about accomplishing a task. I have a app with 5 tab bar items I need to program one of the tabs to call a modal dialog box that has three options. 1. Cancel 2. Call Us 3. Email Us. if the user pushes call us the device should start calling our 800 number if they press email us then it should open the email client and put our sales or support team automatically in the "to:" section. Please provide me with some direction or perhaps a tutorial on how to something like this. Thank you for your help.
I have added these tasks in a different view using two UIButtons. if you come up with a way to do a popOver please let me know. If not I will go with what I have. Thank you. The code I used for email and call (both can be found by doing a SO search) in case anyone else looks in on this thread are as follows:
EMAIL
-(IBAction)emailUs:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailViewcontroller = [[MFMailComposeViewController alloc]init];
mailViewcontroller.mailComposeDelegate = self;
[mailViewcontroller setToRecipients:[NSArray arrayWithObjects:#"CustomerService#laserpros.com", nil]];
[mailViewcontroller setTitle:#"Email Us"];
[mailViewcontroller setSubject:#"Email Us"];
[mailViewcontroller setMessageBody:#"Your message goes here" isHTML:NO];
[self presentViewController:mailViewcontroller animated:YES completion:nil];
}
else
{
NSLog(#"Device is unable to send email in its current state.");
}
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
CALL
-(IBAction)callUs:(id)sender
{
NSURL *phoneNumber = [NSURL URLWithString:#"telprompt://18885585277"];
[[UIApplication sharedApplication] openURL:phoneNumber];
}

iPhone - Leaks in MessageUI framework?

I use MFMailComposeViewController to send emails in my app.
When I run my app with Instruments,
I see a leak after I tapped to send the email.
Leaked Object # Address Size Responsible Library Responsible Frame
MutableMessageHeaders,1 0x6be950 32 Bytes MessageUI +[MFComposeTypeFactory headersFromDelegate:]
_MFOutgoingMessageBody,1 0x1190ed0 32 Bytes Message -[MessageWriter createMessageWithPlainTextDocumentsAndAttachments:headers:]
Do you know how to fix it,
is this a leak in MessageUI framework?
- (void)showMailComposer
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Subject"];
NSString *emailBody = #"Email body";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
#pragma mark -
#pragma mark Dismiss Mail/SMS view controller
// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the
// message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
Yeah, looks like it. But at a total of 64 bytes per sent email, it’s not one you should be worried about.

how can i send mail with out composer splash screen

i need to send mail in my application.
for that my code is,
MFMailComposeViewController * mailView = [[MFMailComposeViewController alloc] init];
[mailView setMailComposeDelegate:self];
[mailView setSubject:#"Some Subject"];
[mailView setToRecipients:self.selectedArray];
[self presentModalViewController:mailView animated:YES];
[mailView release];
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[controller dismissModalViewControllerAnimated:YES];
}
for that i am getting the splash screen like this.
is it possible to send mail without this splash screen.
i need to send mail in background.
can any one please suggest me.
Thank u in advance.
if you don't want to use the composer you have to write your own smtp client.
I've never tried it but from what I've heard skpsmtpmessage should do the trick.

Problem MFMessageComposerViewController in iPhone sdk

I am trying to implement a SMS application. In that when I tried to send my sms I got an exception at [self.navigationController presentModalViewController:picker animated:YES];. I am very new to this. Can you guys please help me?. My code is as follows.
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.delegate = self;
picker.recipients = [NSArray arrayWithObject:#"123456789"]; // your recipient number or self for testing
picker.body = #"test from OS4";
[self.navigationController presentModalViewController:picker animated:YES];
[picker release];
My Log message is as follows,
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <UINavigationController: 0x5b2c120>.
Thanks in Advance,
S.
The message means picker is nil, i.e. the MFMessageComposeViewController is not created successfully.
Make sure [MFMessageComposeViewController canSendText] returns YES, i.e..
if (![MFMessageComposeViewController canSendText]) {
// show message box for user that SMS cannot be sent
} else {
MFMessageComposeViewController* picker = ...;
...
}
Most probably you are testing this in your iPhone simulator, MFMessageComposeViewController does not work on a simulator and returns nil
Three things come to mind.
First, have you declared your view controller class to be implement MFMailComposeViewControllerDelegate? And have you defined mailComposeController:didFinishWithResult:error: ?
Second, you could just have: [self presentModalViewController:picker animated:YES];
Third, are you sure that picker is non-nil?
The main reason that the modal view will throw a nil exception usually has to do with the device under test not having an email account configured in settings (hence the other comment about the modal view not working in the simulator). #KennyTM's answer is a great way to handle this. Just popup an alert dialog notifying the user.

MFMailComposeViewController does not send mail

I am trying to send mail using MFMailComposeViewController. Everything works, except that mails do not get sent, and I always get MFMailComposeResultFailed.
Any pointers? I am NOT using the simulator, and sending mail does work from my device. I do have a connection (testing via Reachability), and [MFMailComposeViewController canSendMail] returns YES.
No compiler warnings in the project, no crashes...
It was a bug in IOS4.
I had both an Exchange mail account and an old, inactive IMAP account on my phone. Apparently, that leads to problems with iOS4. The mails actually were stuck in the outbox. Once I removed the inactive IMAP account, everything worked as expected.
Some readers might be facing this problem:
Make sure you implement the <MFMailComposeViewControllerDelegate> protocol
Here's the code:
// in TestViewController.h
#interface TestViewController : UIViewController<MFMailComposeViewControllerDelegate>
#end
// in TestViewController.m
#interface TestViewController ()
#end
#implementation
- (void) compose {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello there"];
[picker setToRecipients:#[]];
// Fill out the email body text
NSString *emailBody = #"Hello, sending a message from my app";
[picker setMessageBody:emailBody isHTML:NO];
// use this function. presentModalViewController:... is deprecated
[self presentViewController:picker animated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
It's difficult to tell without seeing a code snippet, however you should check the following:
1) you have correctly set the MFMailComposeViewController's delegate and implemented its delegate methods;
2) you have set the mail subject using setSubject:
3) you have set the message body using setMessageBody:isHTML:
and optionally set an attach using addAttachmentData:mimeType:fileName:
4) you have presented to the user your mail compose view controller using something like
[self presentModalViewController:mcvc animated:YES];
Hope this helps.