I am trying to use the MFMailComposeViewController, I have set all the fields I want to be set as follows :
MFMailComposeViewController *message = [[MFMailComposeViewController alloc] init];
[message setMessageBody:#"My message here" isHTML:NO];
[message setToRecipients:[NSArray arrayWithObject:#"my#domain.com"]];
[message setSubject:#"Request Info"];
message.mailComposeDelegate = self;
// Present mail view controller on screen
UINavigationController *navController = (UINavigationController *)[[[[UIApplication sharedApplication] delegate] window] rootViewController];
[navController presentViewController:message animated:YES completion:NULL];
However when the mail compose window comes up the only field which is set is the Subject and nothing else, the body, the to field are all empty. What am I missing?
Test it on a real device with mail account set.
Related
I'm trying to present a MFMessageComposeViewController modally.
MFMessageComposeViewController *controller =[[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"Welcome to my app!";
controller.recipients = [NSArray arrayWithObjects:#"99999999", nil];
controller.messageComposeDelegate = self;
[self presentViewController:controller
animated:TRUE
completion:nil];
}
The navigation bar of the MFMessageComposeViewController appears transparent.
The controller is appearing like this:
Any ideas how to fix this?
Thanks,
Daniel
You've made changes to the navigation bar using the appearance proxy. Either revert those changes, or override them directly on MFMessageComposeViewController's navigation bar.
Im making sending an email available for the user with this code:
MFMailComposeViewController *vc = [MFMailComposeViewController new];
[vc setSubject:#"Test Subject"];
[vc setMessageBody:#"Test Body" isHTML:NO];
[vc setMailComposeDelegate:self];
[self presentViewController:vc animated:YES completion:nil];
This opens a ViewController with all the stuff you need to sen an email, but it completely wipes everything from the ViewController the user is previously on. It only removes the subviews because the root view is still there because the backgroundColor is still the same.
I have already tried initWithRootViewController: but it crashes.
What is happening?
I found the bug... It wasn't in the code above. It seems the viewWillDissapear: is getting called when presenting the mailVC :/
In there I have code to remove every subview, so yeah, found the problem thanks anyways for those who answered and sorry for the inconvenience.
I'm not sure what you mean by "completely wipes everything". But suposing this is for iPad (and not iPhone), when presenting a view controller it goes full screen by default. If you want to change that, you have to set the modalPresentationStyle of the presented view controller (MFMailComposeViewController in your case)
Your code would look like this:
MFMailComposeViewController *vc = [MFMailComposeViewController new];
[vc setSubject:#"Test Subject"];
[vc setMessageBody:#"Test Body" isHTML:NO];
[vc setMailComposeDelegate:self];
vc.modalPresentationStyle = UIModalPresentationFormSheet; //You can use custom size too
[self presentViewController:vc animated:YES completion:nil];
I'm trying to show a popover with a title, creating a root view controller and instantiating it with my viewController. But, when I show the popover, the content is not shown. Here is the code:
UIViewController *popContentViewController = [[sb instantiateViewControllerWithIdentifier:#"videosTutoriais"] init];
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:popContentViewController];
_popover = [[UIPopoverController alloc] initWithContentViewController:controller];
_popover.delegate = self;
[popContentViewController release];
[controller release];
//dados.myPopoverController = popOverController;
[[self popover] presentPopoverFromRect:ancora.bounds inView:ancora permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Just to be more specific, the title of popover appears normally, but the content doesn't.
Just double check that popContentViewController is not nil. You have the identifier #"videosTutoriais" which looks like it might be a scanning error.
From your code, you are releasing the controller before you display in on the screen. Try releasing it after or in the dealloc method. If you are unsure about memory management. I suggest you try ARC instead to avoid silly errors and mistakes such as this.
The code looked like this:
sb = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
UINavigationController *controller = [[sb instantiateViewControllerWithIdentifier:#"navTutorial"] init];
_popover = [[UIPopoverController alloc] initWithContentViewController:controller];
[[self popover] presentPopoverFromRect:ancora.bounds inView:ancora permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[controller release];
My app has a common class that displays an actionSheet whenever "Contact Us" is clicked from any one of the many NIBs.
If the user chooses "Email Us" from the actionSheet popup, I'd like to call the email methods from the same common class. After researching I implemented this:
-(void)SendEmail {
rootViewController = (UIViewController*)
[(AppDelegate*)[[UIApplication sharedApplication] delegate] viewController];
// compose
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = rootViewController;
//format message
NSArray *recipientsArray = [[NSArray alloc] initWithObjects:#"support#somename.com", nil];
[controller setToRecipients:recipientsArray];
[controller setSubject:[NSString stringWithFormat:#"A question about %#",string]];
[controller setMessageBody:outputMutString isHTML:YES];
//send
if (controller) [rootViewController presentModalViewController:controller animated:YES];
}
//didFinishWithResult
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error;{
if (result == MFMailComposeResultSent) {
}
[rootViewController dismissModalViewControllerAnimated:YES];
}
This will launch a new email, however:
The didFinishWithResult doesn't work as the modal view is not removed either after sending the email or pressing the Cancel button
I am getting this warning: assigning to 'id' from incompatible type 'UIViewController *__strong'
controller.mailComposeDelegate = rootViewController;
Help appreciated.
You need to set your rootViewController as adopting the delegate MFMailComposeViewControllerDelegate.
i.e. in your RootViewController.h file, add that part to the interface declaration so that it looks similar to:
#interface RootViewController : UIViewController <MFMailComposeViewControllerDelegate>
I have the following block of code which works fine in the simulator and on most devices, on some devices however (all on the same iOS version 4.2.1) the app is crashing when it gets to the [mailComposer release] call, does anyone have any insight on why this would be happening?
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:[self.webView stringByEvaluatingJavaScriptFromString:#"document.title"]];
[mailComposer setMessageBody:[NSString stringWithFormat:#"Hello, \n\n Here is the link we discussed. \n %#", [self.webView.request URL]] isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
I had this exact same problem and I really have NO idea why it would crash, because presentModalViewController is supposed to retain the view controller. After fighting with it, I finally just added a property on my view controller which retained the reference to the mfMailComposeViewController and it worked fine. :/
MFMailComposeViewController* mfMailComposeViewController;
#property (nonatomic, retain) MFMailComposeViewController *mfMailComposeViewController;
then..
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:subject];
[controller setBody:body];
self.mfMailComposeViewController = controller;
[controller release];
Ok so I managed to figure out what was causing my issue with the help of my new iPad 2.
The issue was caused by not having any mail accounts configured, simply adding
if ([MFMailComposeViewController canSendMail])
before I create and present the view prevents the crashing, in my else block I added an UIAlertView to let the user know they cannot access that feature without first configuring a mail account.