i have my tabbar and i can hide this tab bar by the following code below but when tapping cancle of iphone mail composer does not return to the default screen can you please guide how can i do this
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#""];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#""];
NSString *emailBody = #"";
[picker setMessageBody:emailBody isHTML:NO];
//[self presentModalViewController:picker animated:YES];
UIViewController *xyz=(UIViewController*)[myMarketsVicAppDelegate getMainTabbarRef];
[xyz presentModalViewController:picker animated:YES];
[picker release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
You must have to implement following Delegates.
UINavigationControllerDelegate
MFMailComposeViewControllerDelegate,
Like this
<MFMailComposeViewControllerDelegate,UINavigationControllerDelegate>.
Above might be an issue, because - If you have not implemented above delegate, It will give you compile time warnings but however it will execute.
Related
I have write code to send mail on button click.But i have email id programatically.
I have output like this.
email#gmail.com Send MailButton
Now when i click on Send MailButton then it open MFMailComposeViewController but to field is empty.Here email#gmail.com is change dynamically it's not fixed.
My code is
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
if([MFMailComposeViewController canSendMail])
{
NSString *emailBody;
emailBody=self.shareString;
//NSLog(#"EMail Body ---- %#",emailBody);
[picker setMessageBody:emailBody isHTML:YES];
[picker becomeFirstResponder];
[self presentModalViewController:picker animated:YES];
}
What should be change here required?
Use following code:
NSArray *tempArray = [[NSArray alloc] initWithObjects:#"abc#gmail.com", nil];
[picker setToRecipients:tempArray];
It's working properly for me.
Thanks,
Hemang.
Well you need to create an array for this first.
-(void)displayComposerSheetEmailUs{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello from the App!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"abc#gmail.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody = #"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
I am trying to get my table view to present a mailcomposerviewcontroller when a cell is selected. I have tried using:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// Set up recipients
if ([arryData objectAtIndex:0]) {
[picker setSubject:#"To You"];
NSArray *toRecipients = [NSArray arrayWithObject:#"emailaddress#here.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody = #"From Me";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
Yet, this gets me a crash and
which is waiting for a delayed presention of <MFMailComposeViewController:
Your code snippet seems to be fine here.
Still go through these steps again if you have missed something for that matter.
http://www.roseindia.net/answers/viewqa/Mobile-Applications/18176-iPhone-MFMailcomposeviewcontroller-example.html
I hope it helps you!
Cheers!!
It is better to check first if the device is configured to sent mails. You can see this link
i'm having troubles with my MFMessageComposeViewController. I would like to use SMS in-app.
Everything work fine for sending SMS, so far so good. But when i hit the cancel button (or send button too) top of my view disapeared but the keyboard did not. It's maybe because i don't use modale view, but only a addSubview.
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled)
{
NSLog(#"Message annulé");
[controller resignFirstResponder];
[controller.view removeFromSuperview];
[controller release];
}
else if (result == MessageComposeResultSent)
{
NSLog(#"Message envoyé");
...
}
else
{
NSLog(#"Message non envoyé");
...
}
}
-(void)sendSMS:(NSString *)bodyOfMessage :(Phone *)recipient
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSMutableArray *toRecipients = [[NSMutableArray alloc]init];
[toRecipients addObject:recipients.phoneNumber];
[picker setRecipients:(NSArray *)toRecipients];
[toRecipients release];
NSString *bodyString = nil;
bodyString = bodyOfMessage;
[picker setBody:bodyString];
[self addSubView:picker.view];
[picker release];
}
}
Any idea ? Had I to use only modalView ?
sorry for spelling mistake...
Thank you. Tommy
Yes, you have to use the modalviewcontroller.
[self presentModalViewController:picker];
Also, you're creating two instances of the MFMessageComposeViewController, first for checking if it can send text and then another to actually show it. I advise to create just one, it's better for the memory :) also the first one is leaking since you didn't release it. Good luck!
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSString *bodyString = nil;
NSMutableArray *toRecipients = [[NSMutableArray alloc]init];
[toRecipients addObject:#"phone here"];
[picker setRecipients:(NSArray *)toRecipients];
[toRecipients release];
bodyString = [NSString stringWithFormat: #"Message body"];
[picker setBody:bodyString];
[self presentModalViewController:picker animated:YES];
[picker release];
}
Try close existing keyboard, before presenting modal view controller with MFMessageComposeViewController:
[self.view endEditing:YES]; //close keyboard if it opened
[self presentModalViewController:messageController animated:YES];
I use MFMailComposeViewController canSendMail in my app everything works great but if there are no accounts on the iPhone or iPad it returns a standard alertview what I would like to change. If I put a alert in the else it will return 2 alerts. Is there a way to change the standard alert it returns? Or at least change the text in it?
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
if ([MFMailComposeViewController canSendMail]) {
controller.mailComposeDelegate = self;
controller.navigationBar.tintColor = [UIColor grayColor];
NSArray *toRecipients = [NSArray arrayWithObject:#"info#info.nl"];
[controller setToRecipients:toRecipients];
[controller setSubject:#"bericht van info"];
[self presentModalViewController:controller animated:YES];
[controller release];
}
else {
}
try one thing.. Move your MFMailComposeViewController initialization code inside the canSendMail block.
Move the alloc of the 'MFMailComposeViewController' inside the if:
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
controller.navigationBar.tintColor = [UIColor grayColor];
NSArray *toRecipients = [NSArray arrayWithObject:#"info#info.nl"];
[controller setToRecipients:toRecipients];
[controller setSubject:#"bericht van info"];
[self presentModalViewController:controller animated:YES];
[controller release];
} else {
// Display custom alert here.
}
You can check if the device can send emails with
[MFMailComposeViewController canSendMail]
And, if not, show the dialog in your side
I've configured a simple MFMailComposeViewController below. If I populate the setToRecipients, everything works fine, the email is sent. If I do not populate the setToRecipients, the mail composer window pops up but all fields remain non-editable.
I thought the MFMailComposeViewController would allow the user to edit the email before sending? Is this possible using the standard controls?
- (IBAction) sendEmail
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:[NSString stringWithFormat:#"Receipt Email - %#",[self.labelDate text]]];
NSString *emailBody = #"This is the message body";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
Never mind guys.... I hadn't resigned first responder of the parent view >.< Resolved by adding [self.parentViewController resignFirstResponder]; [self becomeFirstResponder];