iPhone - Leaks in MessageUI framework? - iphone

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.

Related

In App Email View doesn't close - iPhone OS 4

I am having difficulties adding the ability for a user to send a support email to myself (the maker of said app). I have gotten it work almost perfectly however the view doesn't close when you click cancel, or when you click send. Thanks for the help!
Here is the code:
MFMailComposeViewController *mail = [[[MFMailComposeViewController alloc] init] autorelease];
mail.mailComposeDelegate = self;
[mail setToRecipients:[NSArray arrayWithObject:#"support#lindahlstudios.com"]];
[mail setSubject:#"Fraction Calculator Lite Support"];
[self presentModalViewController:mail animated:YES];
You're setting self to be the MFMailComposeViewController's delegate. In mailComposeController:didFinishWithResult:error: be sure to call
[self dismissModalViewControllerAnimated:YES];
like so:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
You need to implement the delegate method from MFMailComposeViewControllerDelegate.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}

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.

Mail comes Without Message content using MFMailComposeViewController in 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?

iPhone: How to Close MFMailComposeViewController?

I'm having difficulties closing an email message that I have raised.
The email opens nicely, but once it is opened it will not close as the mailComposeController:mailer didFinishWithResult:result error:error handler never gets invoked.
As far as I can tell I have all the bits in place to be able to do this.
Anyone any ideas of what I can look at?
Here is how I raise the email:
-(IBAction)emailButtonPressed
{
NSString *text = #"My Email Text";
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.delegate = self;
[mailer setSubject:#"Note"];
[mailer setMessageBody:text isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
and later in the class I have this code to handle the close (but it never gets called):
-(void)mailComposeController:(MFMailComposeViewController *)mailer didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self becomeFirstResponder];
[mailer dismissModalViewControllerAnimated:YES];
}
My header file is defined as:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#interface myViewController : UIViewController <UIActionSheetDelegate, UIAlertViewDelegate, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate>
Thanks
Iphaaw
You are setting the delegate wrong, the delegate property in MFMailComposeViewController is called mailComposeDelegate, so it should be:
mailer.mailComposeDelegate = self;
Another possible error I can see is calling dismissModalViewControllerAnimated: on mailer - you should send this message to the view controller who presented the mail interface - self in this case:
[self dismissModalViewControllerAnimated:YES];
I wrote "possible error" because it might actually work if iOS routes the message through responder chain, anyway - the documentation says it should be send to presenter.

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.