Iphone - adding an MFMailComposeViewController view (in-app email)

I spent the last two days just trying to enable sending email from my application. Hoping that one of the smart people here will help me. presentModalViewController does not work for me (just crashing the application without explanation), so I have to add the MFMailComposeViewController view. Here is my attempt:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; controller.mailComposeDelegate = self; [controller setSubject:@"test subject"]; [controller setMessageBody:@"this is the message body" isHTML:NO]; // [self presentModalViewController:controller animated:YES]; //this crashes the app //so I try this instead: controller.view.frame = CGRectMake(0,0,480,320); [self.view addSubview:controller.view]; [controller release]; 

What is added to the screen is just the theme panel, with cancel and send buttons. None of the text fields (To :, Cc :, Subject, body) are displayed. Why are they not part of the MFMailComposeViewController view and how to display them?

0
email iphone uiviewcontroller
source share
5 answers

Honestly, you should use presentModalViewController . Instead of making your way around the SDK, consider debugging a crash. Turn on the debugger and check to see if there are any exceptions logged in the console. Check for alarms, etc.

Also, make sure that self is the proper delegate and subclass of the UIViewController.

+2
source share

I solved this problem:

try NOT:

 MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; 

but this:

 MFMailComposeViewController *mailComposeViewController = [MFMailComposeViewController new]; 
+2
source share

Instead, you should try:

[[self navigationController] presentModalViewController...];

Since this is the right way to introduce it. Unfortunately, an attempt to add your view manually, unfortunately, is completely wrong and will never work.

+1
source share

Well, I decided that I needed to create a dummy view controller, otherwise the dash would not slide.

I am creating a class called Sys_Mail , which is @interface Sys_Mail : UIViewController <MFMailComposeViewControllerDelegate>

and then I basically create a view controller for the root view. I struggled with the portrait / landscape for several hours, but decided that if you attach the view controller to the top level view (which contains my landscape transformation), then it slides in the form of a landscape window. There is only one visual glitch, the parent window moves for several seconds while the new window slides, this is a side effect of the landscape transformation doing odd things to parents ....

To get the landscape orientation in a sliding window, you must declare a method in the Sys_Mail class that processes the autorotation message:

 //======================= // shouldAutorotateToInterfaceOrientation //======================= // see if this ever gets called for the view controller -(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation { if (TRACE) printf ("shouldAutorotateToInterfaceOrientation\n"); return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); // or whatever orientation is needed } 

gMasterView variable refers to my top-level view (which has a landscape transform and is attached to the window). Subviews don't seem to work, viewing controllers is terrible. THEY ARE MORE DESIGN CARPATHIANS. I need full control over my views, not some kind of Microsoft MFC.

 Sys_Mail* g_root_vc; if (g_root_vc == nil) { // create an empty view controller so we have something to work with g_root_vc = [[Sys_Mail alloc] init]; g_root_vc.view = (UIView*) gMasterView; } 

therefore this

+1
source share

I have the same error, and finally I can fix it by sending a message to presentModalViewController [self navigationController].

Here is my code:

 // Create the Mail composer view controller MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; // Set the view controller delegate controller.mailComposeDelegate = self; // Set recipients, if you want [controller setToRecipients:recipients]; // Set subject, if you want [controller setSubject:@"The subject"]; // Set message body, if you want [controller setMessageBody:@"The message body" isHTML:YES]; // isHTML -> YES/NO depending the message body // Present the view controller [[self navigationController] presentModalViewController:controller animated:YES]; // Memory management [controller release]; 

Hope this helps!

0
source share

All Articles